1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// SPDX-License-Identifier: MIT OR Apache-2.0
//! Loading a tree-sitter parser as a typed, actionable error.
//!
//! `outline`, `query` and `syntax_check` all call
//! [`tree_sitter_language_pack::get_parser`]. That call can fail for two very
//! different reasons, and the crate reports both as its own `Error`, which
//! `anyhow` then carried as an untyped string: the process exited 255 with
//! "internal error" and a suggestion telling the user to file a bug report.
//!
//! The two reasons are not the same:
//!
//! - the network is unreachable and the grammar was never downloaded, which is
//! [`AtomwriteError::GrammarUnavailable`] — exit 69, retry once online;
//! - the grammar name is not one the pack knows, which is
//! [`AtomwriteError::InvalidInput`] — exit 65, the `--language` value is wrong.
//!
//! A user who gets the first one must not be told the tool is broken. One
//! function decides, and the three verbs share it so they cannot disagree.
use Result;
use Error as PackError;
use crateAtomwriteError;
/// Build a parser for `language`, translating the pack's error.
///
/// Returns [`AtomwriteError::GrammarUnavailable`] when the failure is about
/// getting the grammar (download, network, cache), and
/// [`AtomwriteError::InvalidInput`] when the failure is about the name itself.
///
/// # Errors
///
/// Returns one of the two variants described above; the caller adds nothing,
/// because the message already names the language and the reason.
/// Load a `Language` value for `language`, translating the pack's error.
///
/// # Errors
///
/// Same two variants as [`parser_for`].
/// Decide which variant a pack error deserves.
///
/// The `LanguageNotFound` variant is about the name, so it is invalid input.
/// Everything else the pack raises while loading (download, manifest, network,
/// dynamic load) is about obtaining the grammar for a name the caller supplied,
/// which is a host precondition and never a defect of this program.