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
70
71
72
73
use camino::Utf8PathBuf;

use miette::Diagnostic;
use std::io;
use std::process::ExitStatus;
use std::time::Duration;

#[derive(Debug, thiserror::Error, Diagnostic)]
pub enum Error {
    #[error("failed to load config")]
    #[diagnostic(
        code(parallax::config),
        help("the config must be a Fennel file; fix the reported syntax or validation error")
    )]
    Config(#[from] mlua::Error),

    #[error("{path}: {message}")]
    #[diagnostic(
        code(parallax::config_invalid),
        help("a config returns {{:variants {{...}} :server (fn ...) :flow (fn ...)}}")
    )]
    ConfigInvalid { path: Utf8PathBuf, message: String },

    #[error("io error: {0}")]
    #[diagnostic(code(parallax::io))]
    Io(#[from] io::Error),

    #[error("the server function failed")]
    #[diagnostic(
        code(parallax::server_function),
        help(
            "the server function must return a table like {{:cmd [\"app\" \"serve\"] :timeout 30}}"
        )
    )]
    ServerFunction(#[source] mlua::Error),

    #[error("could not start the server command: {cmd}")]
    #[diagnostic(
        code(parallax::server_spawn),
        help("the first word of :cmd must name an executable on PATH or a path to one")
    )]
    ServerSpawn {
        cmd: String,
        #[source]
        source: io::Error,
    },

    #[error("{variant}: the server exited before the handshake ({status})\n{tail}")]
    #[diagnostic(
        code(parallax::server_exited),
        help(
            "the app must write JSON with a url to $PARALLAX_HANDSHAKE once it listens; the quoted text is the end of its server.log"
        )
    )]
    ServerExited {
        variant: String,
        status: ExitStatus,
        tail: String,
    },

    #[error("{variant}: no handshake from the server after {timeout:?}\n{tail}")]
    #[diagnostic(
        code(parallax::server_timeout),
        help(
            "the app must write JSON with a url to $PARALLAX_HANDSHAKE once it listens; the quoted text is the end of its server.log"
        )
    )]
    ServerTimeout {
        variant: String,
        timeout: Duration,
        tail: String,
    },
}