Skip to content

Commit

Permalink
fix: graceful error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
alesbrelih committed Apr 3, 2024
1 parent e8e07b6 commit 403b446
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions gitlab-ci-ls-parser/src/treesitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,29 @@ impl Treesitter for TreesitterImpl {
let tree = match parser.parse(content, None) {
Some(t) => t,
None => {
error!("could not parse treesitter Q; got Q:\n{}", query_source);
error!(
"could not parse treesitter content; got content:\n{}",
content
);

return None;
}
};

let root_node = tree.root_node();

let query = Query::new(language(), query_source.as_str()).unwrap();
let query = match Query::new(language(), query_source.as_str()) {
Ok(q) => q,
Err(err) => {
error!(
"could not parse treesitter query; got content:\n{}\ngot error: {}",
query_source, err,
);

return None;
}
};

let mut cursor_qry = QueryCursor::new();
let matches = cursor_qry.matches(&query, root_node, content.as_bytes());

Expand Down

0 comments on commit 403b446

Please sign in to comment.