nreplops_tool/
error.rs

1// error.rs
2// Copyright 2022 Matti Hänninen
3//
4// Licensed under the Apache License, Version 2.0 (the "License"); you may not
5// use this file except in compliance with the License. You may obtain a copy of
6// the License at
7//
8//     http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13// License for the specific language governing permissions and limitations under
14// the License.
15
16use std::io;
17
18use crate::{
19  clojure::lex,
20  version::{Version, VersionRange},
21};
22
23#[derive(Debug, thiserror::Error)]
24pub enum Error {
25  #[error("too old nr ({0}), the script requires version {1}")]
26  TooOldVersion(Version, VersionRange),
27  #[error("too new nr ({0}), the script requires version {1}")]
28  TooNewVersion(Version, VersionRange),
29  #[error("No input")]
30  NoInput,
31  #[error("file {0} not found")]
32  NotFound(String),
33  #[error("cannot read stdin")]
34  CannotReadStdIn,
35  #[error("cannot read file {0}")]
36  CannotReadFile(String),
37  #[error("cannot write file {0}")]
38  CannotWriteFile(String),
39  #[error("broken stdout pipe")]
40  CannotWriteStdOut,
41  #[error("broken stderr pipe")]
42  CannotWriteStdErr,
43  #[error("bad port file {0}")]
44  CannotParsePortFile(String),
45  #[error("cannot resolve the IP address for the domain {0}")]
46  DomainNotFound(String),
47  #[error(
48    "the nREPL server address not specified; try using the --port or \
49    --port-file option or ensure that there is a port file .nrepl-port \
50    in the current working directory or its ancestors"
51  )]
52  NotSpecified,
53  #[error("unknown error")]
54  Unknown,
55  #[error("stdin conflict")]
56  StdInConflict,
57  #[error("bad stdin")]
58  BadStdIn,
59  #[error("bad source file")]
60  BadSourceFile,
61  #[error("template arguments must be utf-8")]
62  NonUtf8TemplateArgument,
63  #[error("non-positional template argument must be named")]
64  UnnamedNonPositionalTemplateArgument,
65  #[error("timeout while waiting for port file")]
66  PortFileTimeout,
67  #[error("cannot find host definition for key \"{0}\"")]
68  HostKeyNotFound(String),
69  #[error(
70    "host key \"{0}\" refers recursively to another host key but this is \
71    not supported yet"
72  )]
73  RecursiveHostKeysNotSupported(String),
74  #[error(
75    "unexpected error while loading for default host configuration: {0}"
76  )]
77  FailedToLoadDefaultHostConfig(io::Error),
78
79  // Related to nREPL connection
80  #[error("failed to connect to host: {0}")]
81  FailedToConnectToHost(io::Error),
82  #[error("unexpected error while receiving from host: {0}")]
83  CannotReceiveFromHost(io::Error),
84  #[error("unexpected error while sending to host: {0}")]
85  CannotSendToHost(io::Error),
86  #[error("host sent corrupted response")]
87  CorruptedResponse,
88  #[error("host disconnected unexpectedly")]
89  HostDisconnected,
90  #[error("host sent unexptected response")]
91  UnexptectedResponse,
92
93  // Related to parsing Clojure
94  #[error("failed to parse result: {0}")]
95  FailedToParseResult(Box<lex::Error>),
96}