Repository navigation
Expand file tree
/
Copy pathExceptions.cs
More file actions
160 lines (139 loc) · 5.48 KB
/
Copy pathExceptions.cs
File metadata and controls
160 lines (139 loc) · 5.48 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
namespace PythonScriptRunner;
/// <summary>Base class of PythonScriptRunner exceptions.</summary>
public abstract class PsrException : Exception
{
/// <summary>Creates the exception.</summary>
/// <param name="message">Message.</param>
/// <param name="innerException">Cause.</param>
protected PsrException(string message, Exception? innerException = null)
: base(message, innerException)
{
}
}
/// <summary>The stage does not exist in the catalog.</summary>
public sealed class StageNotFoundException : PsrException
{
/// <summary>Creates the exception.</summary>
/// <param name="stageKey">Requested key.</param>
public StageNotFoundException(string stageKey)
: base($"Stage '{stageKey}' was not found.")
{
StageKey = stageKey;
}
/// <summary>Requested key.</summary>
public string StageKey { get; }
}
/// <summary>The stage exists but not in the requested version.</summary>
public sealed class VersionNotFoundException : PsrException
{
/// <summary>Creates the exception.</summary>
/// <param name="key">Stage or pipeline key.</param>
/// <param name="version">Requested version.</param>
public VersionNotFoundException(string key, int version)
: base($"Version {version} of '{key}' was not found.")
{
Key = key;
Version = version;
}
/// <summary>Stage or pipeline key.</summary>
public string Key { get; }
/// <summary>Requested version.</summary>
public int Version { get; }
}
/// <summary>The version exists but cannot run (it is a draft or was archived).</summary>
public sealed class VersionNotRunnableException : PsrException
{
/// <summary>Creates the exception.</summary>
/// <param name="key">Stage or pipeline key.</param>
/// <param name="version">Requested version.</param>
/// <param name="status">Current status of the version.</param>
public VersionNotRunnableException(string key, int version, VersionStatus status)
: base($"Version {version} of '{key}' is {status} and cannot run; only published versions run.")
{
Key = key;
Version = version;
Status = status;
}
/// <summary>Stage or pipeline key.</summary>
public string Key { get; }
/// <summary>Requested version.</summary>
public int Version { get; }
/// <summary>Current status of the version.</summary>
public VersionStatus Status { get; }
}
/// <summary>The run does not exist (or is beyond the retention).</summary>
public sealed class RunNotFoundException : PsrException
{
/// <summary>Creates the exception.</summary>
/// <param name="runId">Requested run.</param>
public RunNotFoundException(RunId runId)
: base($"Run {runId} was not found.")
{
RunId = runId;
}
/// <summary>Requested run.</summary>
public RunId RunId { get; }
}
/// <summary>The stored file does not exist (or is beyond the retention).</summary>
public sealed class ArtifactNotFoundException : PsrException
{
/// <summary>Creates the exception.</summary>
/// <param name="artifactId">Requested file.</param>
public ArtifactNotFoundException(ArtifactId artifactId)
: base($"Artifact {artifactId} was not found.")
{
ArtifactId = artifactId;
}
/// <summary>Requested file.</summary>
public ArtifactId ArtifactId { get; }
}
/// <summary>One invalid input.</summary>
/// <param name="Field">Field path (e.g. <c>coeficientes[2]</c>).</param>
/// <param name="Code">Stable code (e.g. <c>MISSING_REQUIRED_INPUT</c>).</param>
/// <param name="Message">Human-readable message.</param>
public sealed record InputError(string Field, string Code, string Message);
/// <summary>The inputs of a call do not match the contract; no run was created.</summary>
public sealed class InputValidationException : PsrException
{
/// <summary>Creates the exception.</summary>
/// <param name="errors">Every invalid input.</param>
public InputValidationException(IReadOnlyList<InputError> errors)
: base("Invalid inputs: " + string.Join("; ", errors.Select(e => $"{e.Field}: {e.Message}")))
{
Errors = errors;
}
/// <summary>Every invalid input.</summary>
public IReadOnlyList<InputError> Errors { get; }
}
/// <summary>The runner, a catalog or a stage definition is misconfigured.</summary>
public sealed class PsrConfigurationException : PsrException
{
/// <summary>Creates the exception.</summary>
/// <param name="message">What is wrong.</param>
/// <param name="innerException">Cause.</param>
public PsrConfigurationException(string message, Exception? innerException = null)
: base(message, innerException)
{
}
}
/// <summary>Thrown by <see cref="RunResult.EnsureSuccess"/> when the run did not succeed.</summary>
public sealed class RunFailedException : PsrException
{
/// <summary>Creates the exception.</summary>
/// <param name="result">The run result.</param>
public RunFailedException(RunResult result)
: base(BuildMessage(result))
{
Result = result;
}
/// <summary>The run result.</summary>
public RunResult Result { get; }
private static string BuildMessage(RunResult result)
{
ArgumentNullException.ThrowIfNull(result);
var error = result.Error;
return error is null
? $"Run {result.Id} ended with status {result.Status}."
: $"Run {result.Id} ended with status {result.Status}: [{error.Kind}{(error.Code is null ? "" : $"/{error.Code}")}] {error.Message}";
}
}