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

catch and report out-of-memory error #1310

Open
bob-carpenter opened this issue Jan 28, 2025 · 4 comments
Open

catch and report out-of-memory error #1310

bob-carpenter opened this issue Jan 28, 2025 · 4 comments

Comments

@bob-carpenter
Copy link
Member

This is from mippeqf (Markus) on the Stan forums:

When the storage directory set under model$sample(output_dir = …) is full, some chains stop unexpectedly with the error message basic_ios::clear: iostream error. If detectable, it would be great if the error message could pass this reason along.

@WardBrian
Copy link
Member

One solution may be to install an extra top-level exception handler in main.cpp which is more specific:

// new:
  } catch (std::system_error &e) {
    // system_error is thrown by std::ofstream but the
    // message is not always helpful, so we also print errno
    std::cerr << e.what() << ": " << std::strerror(errno) << std::endl;
    return cmdstan::return_codes::NOT_OK;
// already there:
  } catch (const std::exception &e) {
    std::cerr << e.what() << std::endl;
    return cmdstan::return_codes::NOT_OK;
  }

Unfortunately, it seems like strerror(errno) is the only way to actually get something useful out of the errors that the iostream throws, but I see conflicting reports about how portable this is

@bob-carpenter
Copy link
Member Author

I think you can make it more specific with bad_alloc. Doc is:

std::bad_alloc is the type of the object thrown as exceptions by the allocation functions to report failure to allocate storage.

@WardBrian
Copy link
Member

That is for out of memory (RAM), not disk space

@bob-carpenter
Copy link
Member Author

After some searching, it seems like @WardBrian's approach with std::strerror(errno) is the only thing that's viable for reporting the exact error. We could trap or inspect if there's been an error multiple ways:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants