Skip to content

Commit

Permalink
feat: added hack to print error properly
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiisol committed Jan 9, 2024
1 parent d9ba94a commit cba6d85
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
10 changes: 9 additions & 1 deletion app/src/components/Tree/Tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ const TreeContext = createContext(null);
function TreeNode({ label, value }) {
const { expandedAll } = useContext(TreeContext);
const [expanded, setExpanded] = useState(false);
const originalValue = value;

if (value?.isError) {
const error = new Error(value.message);

error.stack = value.stack.join('\n');
value = error;
}

const isComplex = typeof value === 'object' && value !== null && !(value instanceof Error);
const length = isComplex ? Object.keys(value).length : 0;
Expand All @@ -24,7 +32,7 @@ function TreeNode({ label, value }) {
function log() {
events.sendMessage({
type: 'request::log',
data: value,
data: originalValue,
});
}

Expand Down
8 changes: 8 additions & 0 deletions extension/devtools/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
return value.toString();
}

if (value instanceof Error) {
return {
isError: true,
message: value.message,
stack: value.stack.split('\n'),
};
}

if (typeof value === 'object') {
if (Array.isArray(value)) {
const clone = [...value];
Expand Down
14 changes: 13 additions & 1 deletion extension/devtools/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,20 @@ function connect() {

port.onMessage.addListener(message => {
if (message.type === 'request::log') {
console.log(message.data);
log(message.data);
}
});
} catch (err) { }
}

function log(value) {
if (value?.isError) {
const error = new Error(value.message);

error.stack = value.stack.join('\n');

console.log(error)
} else {
console.log(value);
}
}

0 comments on commit cba6d85

Please sign in to comment.