From 74414fc26a1ff8b22eed678341a0c086baf8c5e0 Mon Sep 17 00:00:00 2001 From: oyyd Date: Mon, 8 Jul 2019 10:38:08 +0800 Subject: [PATCH] src: reduce redundant "error:" for `inspect` and `findrefs` When `inspect` or `findrefs` an invalid expr, llnode will print an error message prefixed with "error: error: error:". This PR will reduce one redundant "error:" for such scenario and it seems that we can't remove the other redundant "error:" by calling SB API only. PR-URL: https://github.com/nodejs/llnode/pull/285 Reviewed-By: Matheus Marchini --- src/llnode.cc | 6 ++---- src/llscan.cc | 6 ++---- test/plugin/inspect-test.js | 16 +++++++++++++++- test/plugin/scan-test.js | 23 +++++++++++++++++++---- 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/llnode.cc b/src/llnode.cc index 76d6d7c9..fd4b068d 100644 --- a/src/llnode.cc +++ b/src/llnode.cc @@ -192,10 +192,8 @@ bool PrintCmd::DoExecute(SBDebugger d, char** cmd, SBExpressionOptions options; SBValue value = target.EvaluateExpression(full_cmd.c_str(), options); if (value.GetError().Fail()) { - SBStream desc; - if (value.GetError().GetDescription(desc)) { - result.SetError(desc.GetData()); - } + SBError error = value.GetError(); + result.SetError(error); result.SetStatus(eReturnStatusFailed); return false; } diff --git a/src/llscan.cc b/src/llscan.cc index 4383c50e..ec9431a7 100644 --- a/src/llscan.cc +++ b/src/llscan.cc @@ -504,10 +504,8 @@ bool FindReferencesCmd::DoExecute(SBDebugger d, char** cmd, SBExpressionOptions options; SBValue value = target.EvaluateExpression(full_cmd.c_str(), options); if (value.GetError().Fail()) { - SBStream desc; - if (value.GetError().GetDescription(desc)) { - result.SetError(desc.GetData()); - } + SBError error = value.GetError(); + result.SetError(error); result.SetStatus(eReturnStatusFailed); return false; } diff --git a/test/plugin/inspect-test.js b/test/plugin/inspect-test.js index 1d06b45c..ebeb545f 100644 --- a/test/plugin/inspect-test.js +++ b/test/plugin/inspect-test.js @@ -546,7 +546,7 @@ function verifyHashMap(t, sess) { const parent = 'hashmap'; const addresses = collectMembers( t, lines.join('\n'), hashMapTests, parent); - verifyMembers(t, sess, addresses, hashMapTests, parent, teardown); + verifyMembers(t, sess, addresses, hashMapTests, parent, verifyInvalidExpr); }); } @@ -614,6 +614,20 @@ function verifyMembers(t, sess, addresses, tests, parent, next) { verifyProperty(t, sess, addresses, 0); } +function verifyInvalidExpr(t, sess) { + sess.send('v8 inspect invalid_expr'); + sess.waitError(/error:/, (err, line) => { + if (err) { + return teardown(t, sess, err); + } + t.ok( + /error: error: use of undeclared identifier 'invalid_expr'/.test(line), + 'invalid expression should return an error' + ); + teardown(t, sess); + }); +} + tape('v8 inspect', (t) => { t.timeoutAfter(15000); diff --git a/test/plugin/scan-test.js b/test/plugin/scan-test.js index 4a63f2a5..13b2cbd4 100644 --- a/test/plugin/scan-test.js +++ b/test/plugin/scan-test.js @@ -22,6 +22,18 @@ tape('v8 findrefs and friends', (t) => { } }); +function testFindrefsForInvalidExpr(t, sess, next) { + sess.send('v8 findrefs invalid_expr'); + sess.waitError(/error:/, (err, line) => { + t.error(err); + t.ok( + /error: error: use of undeclared identifier 'invalid_expr'/.test(line), + 'invalid expression should return an error' + ); + next(); + }); +} + function test(executable, core, t) { const sess = common.Session.loadCore(executable, core, (err) => { t.error(err); @@ -32,7 +44,6 @@ function test(executable, core, t) { sess.send('version'); }); - sess.linesUntil(versionMark, (err, lines) => { t.error(err); t.ok(/\d+ Class/.test(lines.join('\n')), 'Class should be in findjsobjects'); @@ -157,7 +168,6 @@ function test(executable, core, t) { sess.send(`v8 findrefs ${match[1]}`); } t.ok(found, 'Zlib should be in findjsinstances'); - // Just a separator sess.send('version'); }); @@ -181,8 +191,13 @@ function test(executable, core, t) { t.error(err) if(hasSymbol) t.ok(/Context\.scopedAPI/.test(lines.join('\n')), 'Should find reference #4'); - sess.quit(); - t.end(); + + // `waitError()` don't share the same `waitQueue` with `wait()` so that + // we add the function below to delay the event registration. + testFindrefsForInvalidExpr(t, sess, () => { + sess.quit(); + t.end(); + }); }); }); }