Closed n8 closed 11 years ago
You should verify the lexer exists before trying to use it. See linguist for examples.
Closing this since clients of pygments.rb should ensure lexer existence.
You should verify the lexer exists before trying to use it. See linguist for examples.
Just fyi: linguist doesn't use pygments.rb directly. Perhaps some dependency does. I hit this error and was wondering the proper way to deal with it, after a bunch of reading docs and messing with pygments,
begin
Pygments.highlight(code, lexer: language)
rescue MentosError => e
Pygments.highlight(code, lexer: 'text')
end
Pygments is awesome, but I've noticed that as soon as I implemented this people trying to use backticks with lexers that don't exist or accidentally using backticks without any intention of adding a code block now get errors from mentos.rb about that lexer not being found.
I was curious from your perspective, if it should be pygments.rb's responsibility to catch the class not found exception and just return the code block with some vanilla/default formatting instead of raising this exception up.
Or should this be an exception dealt with higher up the stack?