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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fixup! src: use basename(argv0) for --trace-uncaught suggestion
  • Loading branch information
addaleax committed Apr 12, 2020
commit 36a3658db634e2a5e4ebf51dec8938f2d8d60526
6 changes: 4 additions & 2 deletions src/node_errors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,10 @@ static void ReportFatalException(Environment* env,
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));
FPrintF(stderr,
"(Use `%s --trace-uncaught ...` to show where the exception "
"was thrown)\n",
fs::Basename(argv0, ".exe"));
addaleax marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
18 changes: 14 additions & 4 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,20 @@ 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);
if (pos == std::string::npos) return str;
return str.substr(pos + 1);
std::string Basename(const std::string& str, const std::string& extension) {
std::string ret = str;

// Remove everything leading up to and including the final path separator.
std::string::size_type pos = ret.find_last_of(kPathSeparator);
if (pos != std::string::npos) ret = ret.substr(pos + 1);

// Strip away the extension, if any.
if (ret.size() >= extension.size() &&
ret.substr(ret.size() - extension.size()) == extension) {
ret = ret.substr(0, ret.size() - extension.size());
}

return ret;
}

inline int64_t GetOffset(Local<Value> value) {
Expand Down
2 changes: 1 addition & 1 deletion src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ BaseObjectPtr<AsyncWrap> CreateHeapSnapshotStream(
} // namespace heap

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

} // namespace node
Expand Down