Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: use basename(argv0) for --trace-uncaught suggestion #32798

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/node_errors.cc
Expand Up @@ -375,8 +375,11 @@ static void ReportFatalException(Environment* env,
}

if (!env->options()->trace_uncaught) {
FPrintF(stderr, "(Use `node --trace-uncaught ...` to show "
"where the exception was thrown)\n");
std::string argv0;
if (!env->argv().empty()) argv0 = env->argv()[0];
if (argv0.empty()) argv0 = "node";
FPrintF(stderr, "(Use `%s --trace-uncaught ...` to show "
"where the exception was thrown)\n", fs::Basename(argv0));
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/node_file.cc
Expand Up @@ -82,6 +82,12 @@ constexpr char kPathSeparator = '/';
const char* const kPathSeparator = "\\/";
#endif

std::string Basename(const std::string& str) {
std::string::size_type pos = str.find_last_of(kPathSeparator);
richardlau marked this conversation as resolved.
Show resolved Hide resolved
if (pos == std::string::npos) return str;
return str.substr(pos + 1);
}

inline int64_t GetOffset(Local<Value> value) {
return IsSafeJsInt(value) ? value.As<Integer>()->Value() : -1;
}
Expand Down
4 changes: 4 additions & 0 deletions src/node_internals.h
Expand Up @@ -396,6 +396,10 @@ BaseObjectPtr<AsyncWrap> CreateHeapSnapshotStream(
Environment* env, HeapSnapshotPointer&& snapshot);
} // namespace heap

namespace fs {
std::string Basename(const std::string& str);
} // namespace fs

} // namespace node

#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
Expand Down