Code used from github: https://github.com/opencontainers/runc/blob/master/libcontainer/rootfs_linux.go#L59
This is the if block to debug for our interest....
if err := mountToRootfs(m, config.Rootfs, config.MountLabel, hasCgroupns); err != nil {
return newSystemErrorWithCausef(err, "mounting %q to rootfs at %q", m.Source, m.Destination)
}
Here in the if condition, there is an error generated thru newSystemErrorWithCausef function and which internally uses generic_error.go, fmt.Sprintf to format the error string.
In our integration, only once it hit this if block. And in the process of getting more details, I wanted to troubleshoot and understand why this happened.
As of now tried using fmt.Printf(........) in line 55 and also just before if block of line 59.
And also tried putting above statement in very first line of prepareRootfs function. And then tried newSystemErrorWithCause(err, "some other message") in the first line of prepareRootfs function. Overall I dont see any information generated with my messages.
Please provide any information to understand more of this issue. Please note I am not looking for why this error might have been caused. I am looking for how to get more information from that function of prepareRootfs.
I'm trying to provide a good experience to users that are using JSON and the parser is on the backend (Ruby).
Most of the time, when you get a badly formatted JSON payload the error is of the format XXX unexpected token at '<entire payload here>'. That's not very user-friendly nor practical.
My question is: Is there a list of the XXX error codes that could help create better error messages that could be understood by beginners and not-really-tech-people?
Thanks!
XXX in this kind of errors is not a special code of the error. It is just a line number from the file where this error was raised. For example, for Ruby 2.5.1 you'll get JSON::ParserError (765: unexpected token at https://github.com/ruby/ruby/blob/v2_5_1/ext/json/parser/parser.rl#L765
You can find a list in the documentation for the module.
Think this covers it:
JSON::JSONError
JSON::GeneratorError
JSON::GenericObject
# The base exception for JSON errors.
JSON::MissingUnicodeSupport
# This exception is raised if the required unicode support is missing on the system. Usually this means that the iconv library is not installed.
JSON::NestingError
# This exception is raised if the nesting of parsed data structures is too deep.
JSON::ParserError
# This exception is raised if a parser error occurs.
JSON::UnparserError
# This exception is raised if a generator or unparser error occurs.
JSON::JSONError is the parent class, so you can rescue from that and provide per-error-class messages as needed.
I feel it's worth noting that in my experience the vast majority of errors relating to JSON are of the class JSON::ParserError. Another common issue worth considering is getting ArgumentError if nil is passed as an argument.
As an example of how this could be used, you could work with something like the following:
begin
JSON.parse(your_json)
rescue JSON::JSONError, ArgumentError => e
{ error: I18n.t(e.to_s) } # <- or whatever you want to do per error
end
Hope that helps - let me know how you get on :)
I want Ruby on Rails app output logs only in JSON so it's edible for most log processing tools. I'm using Lograge for that. However, when there is an exception raised, not only JSON logline is shown, but also the exception's name and its backtrace. This breaks JSON parsing.
Example of an output:
{"method":"GET","path":"/raise_exception_path","format":"html","controller":"ApplicationController","action":"raise_exception_path","status":500,"error":"RuntimeError: exception is raised error","duration":46.0,"view":0.37,"db":0.0,"exception":["RuntimeError","exception is raised"],"exception_object":"exception is raised ","#timestamp":"2019-07-03T08:18:16.979Z","#version":"1","message":"[500] GET /version (ApplicationController#version)"}
RuntimeError (exception is raised):
app/controllers/application_controller.rb:6:in `version'
I've tried Rails' log silencers/filters, but they'd only deal with the backtrace - not the exception name itself. A line RuntimeError (exception is raised): is still printed to the console.
Also, I thought maybe it's just enough to redirect STDERR to /dev/null, but apparently these exceptions and their backtrace are printed to STDOUT.
My application configuration:
config.logger = ActiveSupport::Logger.new(STDOUT)
config.lograge.enabled = true
config.lograge.base_controller_class = 'ActionController::API'
config.lograge.formatter = Lograge::Formatters::Logstash.new
config.lograge.custom_options = lambda do |event|
{
exception: event.payload[:exception], # ["ExceptionClass", "the message"]
exception_object: event.payload[:exception_object] # the exception instance
}
end
$stderr.reopen("/dev/null", "w")
The expected result would be that on production I have a stream of JSON-only loglines, ideally printed to STDOUT, without any exceptions or stacktraces.
{"method":"GET","path":"/","format":"html","controller":"TimezoneController","action":"timezone","status":200,"duration":11.56,"view":2.0,"db":0.0,"exception":null,"exception_object":null,"#timestamp":"2019-07-03T08:18:13.954Z","#version":"1","message":"[200] GET / (TimezoneController#timezone)"}
{"method":"GET","path":"/version","format":"html","controller":"ApplicationController","action":"version","status":500,"error":"RuntimeError: earth is flat error","duration":46.0,"view":0.37,"db":0.0,"exception":["RuntimeError","earth is flat error"],"exception_object":"earth is flat error","#timestamp":"2019-07-03T08:18:16.979Z","#version":"1","message":"[500] GET /version (ApplicationController#version)"}
{"method":"GET","path":"/","format":"html","controller":"TimezoneController","action":"timezone","status":200,"duration":11.56,"view":2.0,"db":0.0,"exception":null,"exception_object":null,"#timestamp":"2019-07-03T08:18:13.954Z","#version":"1","message":"[200] GET / (TimezoneController#timezone)"}
{"method":"GET","path":"/version","format":"html","controller":"ApplicationController","action":"version","status":500,"error":"RuntimeError: earth is flat error","duration":46.0,"view":0.37,"db":0.0,"exception":["RuntimeError","earth is flat error"],"exception_object":"earth is flat error","#timestamp":"2019-07-03T08:18:16.979Z","#version":"1","message":"[500] GET /version (ApplicationController#version)"}
I'm trying to draw a model using DirectX (following this tutorial: https://github.com/Microsoft/DirectXTK/wiki/Rendering-a-model?fbclid=IwAR3A0mw9rzjJHrN3mwgSb9a6oKqNgiDiAnnfkVLIIQVca9Og6cvfvscuVfE).
I've add my model.cmo file with Add existing item and following line to Game::CreateDevice()
m_model = Model::CreateFromCMO(m_d3dDevice.Get(), L"model.cmo", *m_fxFactory);
I can't build and run my project because of exception on aboved line
Unhandled exception at 0x747318A2 in directX_project.exe: Microsoft C++ exception: std::exception at memory location 0x00B3F738. occurred
I will appreciate any tips on how to resolve or debug that issue
You should enable "break on C++ exception" for the debugger as indicated in the instructions here for std::exception so you can see exactly what code triggered the exception.
Note that more recent versions of the DirectX Tool Kit provide more debug output for those kinds of failures which are probably 'file not found' or similar issue.
The DirectX Tool Kit also implements the what method for it's C++ exceptions, so you can use this code to get more detail:
try
{
m_model = Model::CreateFromCMO(m_d3dDevice.Get(), L"model.cmo", *m_fxFactory);
}
catch (std::exception& ex)
{
std::cout << ex.what();
// Do some error handling here or call throw to re-throw it
}
I'm writing tests for a Ruby Rails application, and I have a block of code that is supposed to catch an error thrown by my Redis server if Ruby cannot connect to it. Currently, the code looks like this:
begin
config.before(:all) { Resque.redis.select 1 }
config.after(:all) { Resque.redis.keys("queue:*").each { |key| Resque.redis.del key } }
rescue Exception
puts "RESCUED REDIS ERROR"
end
According to the stack trace when I try to run the tests, the second line of that code snippet -- config.before(:all) {...} -- throws a Redis::CannotConnectError. After a lot of "e.class.superclass.superclass..." commands, I determined that this error inherited from StandardError.
After that I got stuck. I tried catching the error with "rescue Redis::CannotConnectError", then "rescue", and finally "rescue Exception", but the error is still thrown. However, I tried the same things in the Ruby command prompt, and the exception was caught every time
Could anyone help me work out what's happening here? Thanks!
The problem is that the blocks passed to before and after are not being executed at the time they're defined; instead, they're being stored and then called later by Rspec before and after each spec file runs.
You'll probably want to move the begin/rescue within the blocks instead:
config.before(:all) do
begin
Resque.redis.select 1
rescue Exception
puts "RESCUED REDIS ERROR"
end
end
# same for config.after(:all)