Skip to content
This repository has been archived by the owner on Feb 12, 2018. It is now read-only.

Commit

Permalink
Don't panic on unknown syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
trishume committed Jun 16, 2016
1 parent 7607c26 commit 0fc75cd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/easy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ impl<'a> HighlightFile<'a> {
let extension = path.extension().and_then(|x| x.to_str()).unwrap_or("");
let f = try!(File::open(path));
let reader = BufReader::new(f);
// TODO use first line detection and don't panic
let syntax = ss.find_syntax_by_extension(extension).unwrap();
// TODO use first line detection
let syntax = ss.find_syntax_by_extension(extension).unwrap_or_else(|| ss.find_syntax_plain_text());
Ok(HighlightFile {
reader: reader,
highlight_lines: HighlightLines::new(syntax, theme),
Expand Down
3 changes: 3 additions & 0 deletions src/parsing/syntax_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ impl SyntaxSet {
/// Good as a fallback when you can't find another syntax but you still want
/// to use the same highlighting pipeline code.
///
/// This syntax should always be present, if not this method will panic.
/// If the way you load syntaxes doesn't create one, use `load_plain_text_syntax`.
///
/// # Examples
/// ```
/// use syntect::parsing::SyntaxSet;
Expand Down

0 comments on commit 0fc75cd

Please sign in to comment.