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

More meaningful message when ~/.rr doesn't exist. #1617

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
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
17 changes: 16 additions & 1 deletion src/TraceStream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,16 @@ static TraceStream::Substream operator++(TraceStream::Substream& s) {
return s;
}

static bool file_exists(const string& file) {
struct stat dummy;
return !file.empty() && stat(file.c_str(), &dummy) == 0
&& S_ISREG(dummy.st_mode);
}

static bool dir_exists(const string& dir) {
struct stat dummy;
return !dir.empty() && stat(dir.c_str(), &dummy) == 0;
return !dir.empty() && stat(dir.c_str(), &dummy) == 0
&& S_ISDIR(dummy.st_mode);
}

static string default_rr_trace_dir() {
Expand Down Expand Up @@ -592,6 +599,14 @@ TraceReader::TraceReader(const string& dir)
}

string path = version_path();
if (!file_exists(path)) {
fprintf(
stderr,
"rr: warning: No traces have been recorded so far.\n"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message might not be true. It might just be that someone did rr replay <path> where <path> is not the name of an rr trace directory.

Also, I think we don't need a separate file_exists check here. If vfile.good() is false then we can assume the file doesn't exist. We should just print a different, better message saying that the trace was not found.

Actually what would be really useful is to change this constructor so that if an error occurs, it returns an error code (an enum) in an out-parameter and the caller can handle it. Then ReplaySession's constructor can forward that error out to its caller, ReplayCommand, which can display the error message. Really the Command classes should be responsible for interacting with the user.

"\n");
exit(EX_DATAERR);
}

fstream vfile(path.c_str(), fstream::in);
if (!vfile.good()) {
fprintf(
Expand Down