@superzerodev/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter.d.ts +127 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +16 -0
- package/dist/adapter.js.map +1 -0
- package/dist/errors.d.ts +158 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +309 -0
- package/dist/errors.js.map +1 -0
- package/dist/executor.d.ts +58 -0
- package/dist/executor.d.ts.map +1 -0
- package/dist/executor.js +157 -0
- package/dist/executor.js.map +1 -0
- package/dist/graph.d.ts +19 -0
- package/dist/graph.d.ts.map +1 -0
- package/dist/graph.js +92 -0
- package/dist/graph.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/planner.d.ts +24 -0
- package/dist/planner.d.ts.map +1 -0
- package/dist/planner.js +56 -0
- package/dist/planner.js.map +1 -0
- package/dist/registry.d.ts +18 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +38 -0
- package/dist/registry.js.map +1 -0
- package/dist/source-archive.d.ts +85 -0
- package/dist/source-archive.d.ts.map +1 -0
- package/dist/source-archive.js +398 -0
- package/dist/source-archive.js.map +1 -0
- package/dist/types.d.ts +95 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +22 -0
- package/dist/types.js.map +1 -0
- package/package.json +35 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider Adapter 契約(P0設計 §5.2)
|
|
3
|
+
*
|
|
4
|
+
* ★ この抽象が P0 → P1 移行の要である。
|
|
5
|
+
*
|
|
6
|
+
* 規律:
|
|
7
|
+
* 1. アダプタにビジネスロジックを書かない。「宣言 → プロバイダ API 呼び出し」の変換だけ。
|
|
8
|
+
* 2. 自前実装(Compute Runtime)も必ずこの裏に置く。自前だからと Control Plane に直接書かない。
|
|
9
|
+
* P0 は DockerComputeAdapter、P1 は FirecrackerComputeAdapter。
|
|
10
|
+
* 3. P1 で NeonAdapter → SuperzeroPostgresAdapter の差し替えが1ファイルで済む状態を維持する。
|
|
11
|
+
*/
|
|
12
|
+
import type { Change, ResourceKind, ResourceRecord, VerifyCheck } from './types.js';
|
|
13
|
+
export interface Logger {
|
|
14
|
+
debug(msg: string, meta?: Record<string, unknown>): void;
|
|
15
|
+
info(msg: string, meta?: Record<string, unknown>): void;
|
|
16
|
+
warn(msg: string, meta?: Record<string, unknown>): void;
|
|
17
|
+
error(msg: string, meta?: Record<string, unknown>): void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 宣言ファイル中の `$SECRET_NAME` 参照を解決する。
|
|
21
|
+
* 平文は Control Plane のメモリ上にしか存在させない(§5.4)。
|
|
22
|
+
* ログへ出さないため、解決結果は必ずこの経路でだけ扱う。
|
|
23
|
+
*/
|
|
24
|
+
export interface SecretResolver {
|
|
25
|
+
/** 見つからない場合は secretNotFound() を throw する */
|
|
26
|
+
resolve(key: string): Promise<string>;
|
|
27
|
+
has(key: string): Promise<boolean>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* アダプタに渡す実行文脈。
|
|
31
|
+
* outputsOf で依存リソースの接続情報を取れるのが要点(PE-2)。
|
|
32
|
+
*/
|
|
33
|
+
export interface AdapterContext {
|
|
34
|
+
environmentId: string;
|
|
35
|
+
/** PlanInput.sourceHash と同じ値。state に控えて次回の比較に使う */
|
|
36
|
+
sourceHash?: string | undefined;
|
|
37
|
+
projectName: string;
|
|
38
|
+
region: string;
|
|
39
|
+
secrets: SecretResolver;
|
|
40
|
+
logger: Logger;
|
|
41
|
+
/**
|
|
42
|
+
* 依存リソースの outputs を取得する。
|
|
43
|
+
* 例: compute アダプタが `outputsOf('database:default').DATABASE_URL` を読む。
|
|
44
|
+
* dependsOn に宣言していない key を要求した場合は throw する。
|
|
45
|
+
*/
|
|
46
|
+
outputsOf(key: string): Record<string, string>;
|
|
47
|
+
/**
|
|
48
|
+
* このデプロイのソースが置かれたローカルディレクトリ。
|
|
49
|
+
* ビルドやマイグレーションなど、ソースを必要とするアダプタが読む。
|
|
50
|
+
* ソースを持たない操作(verify など)では未設定。
|
|
51
|
+
*/
|
|
52
|
+
workspaceDir?: string;
|
|
53
|
+
/** 中断シグナル。長時間かかる create/update は必ず尊重する */
|
|
54
|
+
signal?: AbortSignal;
|
|
55
|
+
}
|
|
56
|
+
/** plan() への入力 */
|
|
57
|
+
export interface PlanInput<TSpec, TState> {
|
|
58
|
+
logicalName: string;
|
|
59
|
+
/** 宣言ファイル側。リソースが削除された場合は null */
|
|
60
|
+
desired: TSpec | null;
|
|
61
|
+
/** Control Plane DB 側。未作成なら null */
|
|
62
|
+
actual: ResourceRecord<TState> | null;
|
|
63
|
+
/**
|
|
64
|
+
* デプロイ対象ソースの内容ハッシュ。呼び出し側が持っているときだけ入る。
|
|
65
|
+
*
|
|
66
|
+
* ★ これが無いと、宣言ファイルが同じままアプリのコードだけ変えた場合に
|
|
67
|
+
* plan が「変更なし」と言い、apply が何もしない。
|
|
68
|
+
* つまり「コードを直して apply する」という最も普通の操作が通らない。
|
|
69
|
+
*
|
|
70
|
+
* ★ plan は副作用を持ってはいけない(PE-6)が、ファイルを読んで
|
|
71
|
+
* ハッシュを取るのは読み取りなので反しない。ただし plan() は同期なので、
|
|
72
|
+
* ハッシュ自体は呼び出し側が先に計算して渡す。
|
|
73
|
+
*/
|
|
74
|
+
sourceHash?: string | undefined;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* すべてのプロバイダ実装が満たす契約。
|
|
78
|
+
*
|
|
79
|
+
* TSpec … 宣言ファイルから切り出したこのリソースの仕様
|
|
80
|
+
* TState … このアダプタが Control Plane DB へ保存する状態
|
|
81
|
+
*/
|
|
82
|
+
export interface ProviderAdapter<TSpec = unknown, TState = unknown> {
|
|
83
|
+
readonly kind: ResourceKind;
|
|
84
|
+
/** 'docker' | 'neon' | 'twilio' | 'ses' ... */
|
|
85
|
+
readonly provider: string;
|
|
86
|
+
/**
|
|
87
|
+
* 副作用を一切持たないこと(PE-6)。
|
|
88
|
+
* desired と actual の差分から Change を組み立てるだけ。
|
|
89
|
+
*/
|
|
90
|
+
plan(input: PlanInput<TSpec, TState>): Change<TSpec>[];
|
|
91
|
+
create(spec: TSpec, ctx: AdapterContext): Promise<TState>;
|
|
92
|
+
/** 冪等であること(PE-1)。同じ spec で何度呼んでも結果が変わらない */
|
|
93
|
+
update(spec: TSpec, actual: TState, ctx: AdapterContext): Promise<TState>;
|
|
94
|
+
destroy(actual: TState, ctx: AdapterContext): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* 実プロバイダから現在の状態を読み直す。drift 検出に使う(PE-5)。
|
|
97
|
+
* plan 実行時に呼ばれ、DB 上の actual を更新してから差分を取る。
|
|
98
|
+
*/
|
|
99
|
+
read(actual: TState, ctx: AdapterContext): Promise<TState>;
|
|
100
|
+
/**
|
|
101
|
+
* 他リソースの環境変数へ注入する接続情報。
|
|
102
|
+
* 例: database アダプタが { DATABASE_URL: '...' } を返す。
|
|
103
|
+
* ここに秘密情報が含まれるため、戻り値をログへ出してはならない。
|
|
104
|
+
*/
|
|
105
|
+
outputs(state: TState): Record<string, string>;
|
|
106
|
+
/**
|
|
107
|
+
* プロバイダ側の実リソースを一意に指す ID。
|
|
108
|
+
*
|
|
109
|
+
* ★ state(アダプタ固有の JSON)とは別に、平らな列として持つために要る。
|
|
110
|
+
* これが無いと「行を失ったが実体は残っている」孤児を見つけられない。
|
|
111
|
+
* Neon プロジェクトもコンテナも課金と資源を消費し続けるので、
|
|
112
|
+
* 横断で引ける形が要る。state を舐めて回るのでは各アダプタの形を知る必要があり、
|
|
113
|
+
* Control Plane がアダプタの内部に依存してしまう。
|
|
114
|
+
*
|
|
115
|
+
* ★ ここに秘密情報を入れてはいけない。DB に平文の列として残り、
|
|
116
|
+
* 管理画面にも出る。指すためだけの ID にすること。
|
|
117
|
+
*/
|
|
118
|
+
externalId(state: TState): string | null;
|
|
119
|
+
/**
|
|
120
|
+
* 自己検証API(§5.10)用のチェック。
|
|
121
|
+
* apply 完了後に自動実行され、エージェントのループを閉じる。
|
|
122
|
+
*/
|
|
123
|
+
verify?(state: TState, ctx: AdapterContext): Promise<VerifyCheck[]>;
|
|
124
|
+
}
|
|
125
|
+
/** 型引数を失わずに登録するためのヘルパ */
|
|
126
|
+
export declare function defineAdapter<TSpec, TState>(adapter: ProviderAdapter<TSpec, TState>): ProviderAdapter<TSpec, TState>;
|
|
127
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,MAAM,EACN,YAAY,EACZ,cAAc,EACd,WAAW,EACZ,MAAM,YAAY,CAAA;AAEnB,MAAM,WAAW,MAAM;IACrB,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAA;IACxD,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAA;IACvD,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAA;IACvD,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAA;CACzD;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,4CAA4C;IAC5C,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IACrC,GAAG,CAAC,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D,4CAA4C;IAC5C,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAEzE,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE3D;;;OAGG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAE1D;;;;OAIG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAE9C;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IAExC;;;OAGG;IACH,MAAM,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAAA;CACpE;AAED,yBAAyB;AACzB,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EACzC,OAAO,EAAE,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,GACtC,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,CAEhC"}
|
package/dist/adapter.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider Adapter 契約(P0設計 §5.2)
|
|
3
|
+
*
|
|
4
|
+
* ★ この抽象が P0 → P1 移行の要である。
|
|
5
|
+
*
|
|
6
|
+
* 規律:
|
|
7
|
+
* 1. アダプタにビジネスロジックを書かない。「宣言 → プロバイダ API 呼び出し」の変換だけ。
|
|
8
|
+
* 2. 自前実装(Compute Runtime)も必ずこの裏に置く。自前だからと Control Plane に直接書かない。
|
|
9
|
+
* P0 は DockerComputeAdapter、P1 は FirecrackerComputeAdapter。
|
|
10
|
+
* 3. P1 で NeonAdapter → SuperzeroPostgresAdapter の差し替えが1ファイルで済む状態を維持する。
|
|
11
|
+
*/
|
|
12
|
+
/** 型引数を失わずに登録するためのヘルパ */
|
|
13
|
+
export function defineAdapter(adapter) {
|
|
14
|
+
return adapter;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAsIH,yBAAyB;AACzB,MAAM,UAAU,aAAa,CAC3B,OAAuC;IAEvC,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 正規化エラー — Agent DX の中核(P0設計 §5.9)
|
|
3
|
+
*
|
|
4
|
+
* 各プロバイダのエラー形式はバラバラなので、ここで1つの形に潰す。
|
|
5
|
+
* エージェントが読んで自力で直せることが唯一の目標。
|
|
6
|
+
*
|
|
7
|
+
* ルール: エラーコードを1つ追加するたびに suggestedFix を必ず書く。
|
|
8
|
+
* 書けないエラーは設計が悪い証拠なので、設計を直す。
|
|
9
|
+
*/
|
|
10
|
+
/** エージェントが読んで自力で修正するための指示 */
|
|
11
|
+
export interface SuggestedFix {
|
|
12
|
+
/** 何をすれば直るか。英語で書く(製品の一次言語は英語 / D3) */
|
|
13
|
+
description: string;
|
|
14
|
+
/** superzero.config.ts への差分。エージェントはこれをそのまま適用できる */
|
|
15
|
+
configPatch?: Record<string, unknown>;
|
|
16
|
+
/** 実行すべきコマンド */
|
|
17
|
+
command?: string;
|
|
18
|
+
}
|
|
19
|
+
/** プロバイダの生エラー。人間のデバッグ用に残す(エージェントは読まなくてよい) */
|
|
20
|
+
export interface ErrorCause {
|
|
21
|
+
provider: string;
|
|
22
|
+
raw: unknown;
|
|
23
|
+
}
|
|
24
|
+
export interface SuperzeroErrorJSON {
|
|
25
|
+
code: string;
|
|
26
|
+
message: string;
|
|
27
|
+
cause?: ErrorCause;
|
|
28
|
+
suggestedFix?: SuggestedFix;
|
|
29
|
+
docsUrl: string;
|
|
30
|
+
}
|
|
31
|
+
export interface SuperzeroErrorInit {
|
|
32
|
+
code: string;
|
|
33
|
+
message: string;
|
|
34
|
+
cause?: ErrorCause;
|
|
35
|
+
suggestedFix?: SuggestedFix;
|
|
36
|
+
/** 省略時は code から自動生成する */
|
|
37
|
+
docsUrl?: string;
|
|
38
|
+
}
|
|
39
|
+
export declare class SuperzeroError extends Error {
|
|
40
|
+
readonly code: string;
|
|
41
|
+
readonly providerCause: ErrorCause | undefined;
|
|
42
|
+
readonly suggestedFix: SuggestedFix | undefined;
|
|
43
|
+
readonly docsUrl: string;
|
|
44
|
+
constructor(init: SuperzeroErrorInit);
|
|
45
|
+
/** CLI の --json、REST API、MCP のすべてがこの形で返す */
|
|
46
|
+
toJSON(): SuperzeroErrorJSON;
|
|
47
|
+
}
|
|
48
|
+
export declare function isSuperzeroError(e: unknown): e is SuperzeroError;
|
|
49
|
+
/**
|
|
50
|
+
* 想定外の例外を正規化エラーへ包む。
|
|
51
|
+
* suggestedFix を持たないので、ここに落ちるケースが出たらエラーコードを追加する合図。
|
|
52
|
+
*/
|
|
53
|
+
export declare function wrapUnknown(provider: string, raw: unknown): SuperzeroError;
|
|
54
|
+
/**
|
|
55
|
+
* エラーコード一覧。
|
|
56
|
+
* 増えるたびにここへ追記し、suggestedFix を持つファクトリを併記する。
|
|
57
|
+
*/
|
|
58
|
+
export declare const ErrorCode: {
|
|
59
|
+
readonly CONFIG_INVALID: "CONFIG_INVALID";
|
|
60
|
+
readonly CONFIG_UNKNOWN_PROVIDER: "CONFIG_UNKNOWN_PROVIDER";
|
|
61
|
+
readonly PLAN_DESTRUCTIVE_CHANGE_BLOCKED: "PLAN_DESTRUCTIVE_CHANGE_BLOCKED";
|
|
62
|
+
readonly PLAN_CIRCULAR_DEPENDENCY: "PLAN_CIRCULAR_DEPENDENCY";
|
|
63
|
+
readonly PLAN_MISSING_DEPENDENCY: "PLAN_MISSING_DEPENDENCY";
|
|
64
|
+
readonly APPLY_CHANGE_FAILED: "APPLY_CHANGE_FAILED";
|
|
65
|
+
readonly SECRET_NOT_FOUND: "SECRET_NOT_FOUND";
|
|
66
|
+
readonly AUTH_INVALID_CREDENTIALS: "AUTH_INVALID_CREDENTIALS";
|
|
67
|
+
readonly AUTH_EMAIL_TAKEN: "AUTH_EMAIL_TAKEN";
|
|
68
|
+
readonly AUTH_WEAK_PASSWORD: "AUTH_WEAK_PASSWORD";
|
|
69
|
+
readonly AUTH_SESSION_EXPIRED: "AUTH_SESSION_EXPIRED";
|
|
70
|
+
readonly AUTH_SESSION_REVOKED: "AUTH_SESSION_REVOKED";
|
|
71
|
+
readonly AUTH_TOKEN_INVALID: "AUTH_TOKEN_INVALID";
|
|
72
|
+
readonly AUTH_SMS_COUNTRY_NOT_ALLOWED: "AUTH_SMS_COUNTRY_NOT_ALLOWED";
|
|
73
|
+
readonly AUTH_SMS_RATE_LIMITED: "AUTH_SMS_RATE_LIMITED";
|
|
74
|
+
readonly AUTH_SMS_NUMBER_BLOCKED: "AUTH_SMS_NUMBER_BLOCKED";
|
|
75
|
+
readonly AUTH_SMS_PROJECT_SUSPENDED: "AUTH_SMS_PROJECT_SUSPENDED";
|
|
76
|
+
readonly AUTH_SMS_CODE_INVALID: "AUTH_SMS_CODE_INVALID";
|
|
77
|
+
/** compute を宣言しているのにソースが届いていない */
|
|
78
|
+
readonly SOURCE_REQUIRED: "SOURCE_REQUIRED";
|
|
79
|
+
/** 送られたソースが上限を超えた */
|
|
80
|
+
readonly SOURCE_TOO_LARGE: "SOURCE_TOO_LARGE";
|
|
81
|
+
/** アーカイブが壊れている、または受け付けない内容を含む */
|
|
82
|
+
readonly SOURCE_INVALID_ARCHIVE: "SOURCE_INVALID_ARCHIVE";
|
|
83
|
+
/** sourceId が見つからない(期限切れ、または既に使い終わっている) */
|
|
84
|
+
readonly SOURCE_NOT_FOUND: "SOURCE_NOT_FOUND";
|
|
85
|
+
readonly COMPUTE_PUBLIC_URL_UNREACHABLE: "COMPUTE_PUBLIC_URL_UNREACHABLE";
|
|
86
|
+
readonly COMPUTE_CONTAINER_EXITED: "COMPUTE_CONTAINER_EXITED";
|
|
87
|
+
readonly COMPUTE_PORT_NOT_PUBLISHED: "COMPUTE_PORT_NOT_PUBLISHED";
|
|
88
|
+
readonly APPLY_DEPENDENCY_OUTPUTS_MISSING: "APPLY_DEPENDENCY_OUTPUTS_MISSING";
|
|
89
|
+
readonly API_UNAUTHORIZED: "API_UNAUTHORIZED";
|
|
90
|
+
readonly ENVIRONMENT_NOT_FOUND: "ENVIRONMENT_NOT_FOUND";
|
|
91
|
+
readonly API_KEY_NOT_FOUND: "API_KEY_NOT_FOUND";
|
|
92
|
+
readonly SIGNUP_NOT_READY: "SIGNUP_NOT_READY";
|
|
93
|
+
readonly SIGNUP_EMAIL_INVALID: "SIGNUP_EMAIL_INVALID";
|
|
94
|
+
readonly SIGNUP_EMAIL_REJECTED: "SIGNUP_EMAIL_REJECTED";
|
|
95
|
+
readonly ORG_SPEND_LIMIT_EXCEEDED: "ORG_SPEND_LIMIT_EXCEEDED";
|
|
96
|
+
readonly ORG_PROJECT_LIMIT_REACHED: "ORG_PROJECT_LIMIT_REACHED";
|
|
97
|
+
/** Free プランでは使えない操作。カード登録(Pro)で解ける */
|
|
98
|
+
readonly BILLING_REQUIRED: "BILLING_REQUIRED";
|
|
99
|
+
readonly BILLING_ALREADY_ACTIVE: "BILLING_ALREADY_ACTIVE";
|
|
100
|
+
/** Pro → Free に戻り、残すプロジェクトを選ぶまでデプロイできない */
|
|
101
|
+
readonly PROJECT_SELECTION_REQUIRED: "PROJECT_SELECTION_REQUIRED";
|
|
102
|
+
readonly PROVIDER_UNEXPECTED_ERROR: "PROVIDER_UNEXPECTED_ERROR";
|
|
103
|
+
};
|
|
104
|
+
export type ErrorCodeValue = (typeof ErrorCode)[keyof typeof ErrorCode];
|
|
105
|
+
export declare function destructiveChangeBlocked(changeKeys: string[]): SuperzeroError;
|
|
106
|
+
/**
|
|
107
|
+
* Control Plane API のトークンが無い・違う。
|
|
108
|
+
*
|
|
109
|
+
* ★ 「無い」と「違う」を区別しない。区別すると、トークンの存在自体が
|
|
110
|
+
* 総当たりの手がかりになる。エージェントにとっては、どちらでも次の行動は同じ。
|
|
111
|
+
*/
|
|
112
|
+
export declare function apiUnauthorized(): SuperzeroError;
|
|
113
|
+
export declare function missingDependency(changeKey: string, missing: string): SuperzeroError;
|
|
114
|
+
export declare function circularDependency(cycle: string[]): SuperzeroError;
|
|
115
|
+
export declare function secretNotFound(key: string): SuperzeroError;
|
|
116
|
+
/** 濫用防止の第1層。設定漏れで全開放にならないよう、必ずこのエラーで止める */
|
|
117
|
+
export declare function smsCountryNotAllowed(countryCode: string, allowed: string[]): SuperzeroError;
|
|
118
|
+
/**
|
|
119
|
+
* コンテナが起動直後に終了した。
|
|
120
|
+
* 起動コマンドの誤り、必須の環境変数の欠落、ビルド成果物の不備などで日常的に起きる。
|
|
121
|
+
* 生の例外にせず、エージェントが次に何を見るべきかまで示す。
|
|
122
|
+
*/
|
|
123
|
+
/**
|
|
124
|
+
* 公開URLに外から到達できない。
|
|
125
|
+
*
|
|
126
|
+
* ★ 内部疎通が緑でもここが赤なら、利用者からは何も見えない。
|
|
127
|
+
* 原因は DNS・証明書・Caddy のルーティングのいずれかで、
|
|
128
|
+
* どれもコンテナの中を見ても分からない。切り分けの起点を示す。
|
|
129
|
+
*/
|
|
130
|
+
export declare function publicUrlUnreachable(url: string, reason: string): SuperzeroError;
|
|
131
|
+
export declare function containerExited(containerId: string): SuperzeroError;
|
|
132
|
+
/**
|
|
133
|
+
* コンテナは起動したが、ホストへのポート公開が完了しなかった。
|
|
134
|
+
*
|
|
135
|
+
* Docker は start の応答後に非同期でポートを割り当てるため、
|
|
136
|
+
* 起動直後の inspect では必ず空に見える(実機で確認済み)。
|
|
137
|
+
* 待っても現れない場合はポートの枯渇か bind の失敗を疑う。
|
|
138
|
+
*/
|
|
139
|
+
export declare function portNotPublished(containerId: string, containerPort: number | undefined, published: unknown): SuperzeroError;
|
|
140
|
+
/**
|
|
141
|
+
* compute を宣言しているのに、ビルドするソースが届いていない。
|
|
142
|
+
*
|
|
143
|
+
* ★ ここを黙って通してはいけない。
|
|
144
|
+
* ソースが読めないと plan は「変更なし」と答え、コードを直したのに
|
|
145
|
+
* 古いコンテナが動き続ける。エージェントからは成功に見える。
|
|
146
|
+
*/
|
|
147
|
+
export declare function sourceRequired(): SuperzeroError;
|
|
148
|
+
/** 送られたソースが上限を超えた。何が超えたかを具体的に言う */
|
|
149
|
+
export declare function sourceTooLarge(actual: string, limit: string): SuperzeroError;
|
|
150
|
+
/**
|
|
151
|
+
* アーカイブが壊れている、または受け付けない内容を含む。
|
|
152
|
+
*
|
|
153
|
+
* ★ 理由を必ず載せる。「不正です」だけだと、送り直す以外の行動が取れない。
|
|
154
|
+
*/
|
|
155
|
+
export declare function sourceInvalidArchive(reason: string): SuperzeroError;
|
|
156
|
+
/** sourceId が見つからない。期限切れか、既に使い終わっている */
|
|
157
|
+
export declare function sourceNotFound(sourceId: string): SuperzeroError;
|
|
158
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,6BAA6B;AAC7B,MAAM,WAAW,YAAY;IAC3B,sCAAsC;IACtC,WAAW,EAAE,MAAM,CAAA;IACnB,mDAAmD;IACnD,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACrC,gBAAgB;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,6CAA6C;AAC7C,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,OAAO,CAAA;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,GAAG,cAAc,CAa7E;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,IAAI,cAAc,CAWhD;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,cAAc,CAQpF;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,cAAc,CAQlE;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAS1D;AAED,2CAA2C;AAC3C,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,cAAc,CAY3F;AAED;;;;GAIG;AACH;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,cAAc,CAehF;AAED,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,cAAc,CAgBnE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM,GAAG,SAAS,EACjC,SAAS,EAAE,OAAO,GACjB,cAAc,CAehB;AAID;;;;;;GAMG;AACH,wBAAgB,cAAc,IAAI,cAAc,CAc/C;AAED,mCAAmC;AACnC,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,cAAc,CAY5E;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,CAanE;AAED,wCAAwC;AACxC,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,CAW/D"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 正規化エラー — Agent DX の中核(P0設計 §5.9)
|
|
3
|
+
*
|
|
4
|
+
* 各プロバイダのエラー形式はバラバラなので、ここで1つの形に潰す。
|
|
5
|
+
* エージェントが読んで自力で直せることが唯一の目標。
|
|
6
|
+
*
|
|
7
|
+
* ルール: エラーコードを1つ追加するたびに suggestedFix を必ず書く。
|
|
8
|
+
* 書けないエラーは設計が悪い証拠なので、設計を直す。
|
|
9
|
+
*/
|
|
10
|
+
const DOCS_BASE = 'https://superzero.dev/errors';
|
|
11
|
+
export class SuperzeroError extends Error {
|
|
12
|
+
code;
|
|
13
|
+
providerCause;
|
|
14
|
+
suggestedFix;
|
|
15
|
+
docsUrl;
|
|
16
|
+
constructor(init) {
|
|
17
|
+
super(init.message);
|
|
18
|
+
this.name = 'SuperzeroError';
|
|
19
|
+
this.code = init.code;
|
|
20
|
+
this.providerCause = init.cause;
|
|
21
|
+
this.suggestedFix = init.suggestedFix;
|
|
22
|
+
this.docsUrl = init.docsUrl ?? `${DOCS_BASE}/${init.code}`;
|
|
23
|
+
}
|
|
24
|
+
/** CLI の --json、REST API、MCP のすべてがこの形で返す */
|
|
25
|
+
toJSON() {
|
|
26
|
+
const json = {
|
|
27
|
+
code: this.code,
|
|
28
|
+
message: this.message,
|
|
29
|
+
docsUrl: this.docsUrl,
|
|
30
|
+
};
|
|
31
|
+
if (this.providerCause)
|
|
32
|
+
json.cause = this.providerCause;
|
|
33
|
+
if (this.suggestedFix)
|
|
34
|
+
json.suggestedFix = this.suggestedFix;
|
|
35
|
+
return json;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function isSuperzeroError(e) {
|
|
39
|
+
return e instanceof SuperzeroError;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 想定外の例外を正規化エラーへ包む。
|
|
43
|
+
* suggestedFix を持たないので、ここに落ちるケースが出たらエラーコードを追加する合図。
|
|
44
|
+
*/
|
|
45
|
+
export function wrapUnknown(provider, raw) {
|
|
46
|
+
return new SuperzeroError({
|
|
47
|
+
code: 'PROVIDER_UNEXPECTED_ERROR',
|
|
48
|
+
message: `Unexpected error from provider "${provider}": ${raw instanceof Error ? raw.message : String(raw)}`,
|
|
49
|
+
cause: { provider, raw },
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* エラーコード一覧。
|
|
54
|
+
* 増えるたびにここへ追記し、suggestedFix を持つファクトリを併記する。
|
|
55
|
+
*/
|
|
56
|
+
export const ErrorCode = {
|
|
57
|
+
// 宣言ファイル
|
|
58
|
+
CONFIG_INVALID: 'CONFIG_INVALID',
|
|
59
|
+
CONFIG_UNKNOWN_PROVIDER: 'CONFIG_UNKNOWN_PROVIDER',
|
|
60
|
+
// プロビジョニング
|
|
61
|
+
PLAN_DESTRUCTIVE_CHANGE_BLOCKED: 'PLAN_DESTRUCTIVE_CHANGE_BLOCKED',
|
|
62
|
+
PLAN_CIRCULAR_DEPENDENCY: 'PLAN_CIRCULAR_DEPENDENCY',
|
|
63
|
+
PLAN_MISSING_DEPENDENCY: 'PLAN_MISSING_DEPENDENCY',
|
|
64
|
+
APPLY_CHANGE_FAILED: 'APPLY_CHANGE_FAILED',
|
|
65
|
+
// シークレット
|
|
66
|
+
SECRET_NOT_FOUND: 'SECRET_NOT_FOUND',
|
|
67
|
+
// 認証
|
|
68
|
+
AUTH_INVALID_CREDENTIALS: 'AUTH_INVALID_CREDENTIALS',
|
|
69
|
+
AUTH_EMAIL_TAKEN: 'AUTH_EMAIL_TAKEN',
|
|
70
|
+
AUTH_WEAK_PASSWORD: 'AUTH_WEAK_PASSWORD',
|
|
71
|
+
AUTH_SESSION_EXPIRED: 'AUTH_SESSION_EXPIRED',
|
|
72
|
+
AUTH_SESSION_REVOKED: 'AUTH_SESSION_REVOKED',
|
|
73
|
+
AUTH_TOKEN_INVALID: 'AUTH_TOKEN_INVALID',
|
|
74
|
+
// SMS(濫用防止 §5.7)
|
|
75
|
+
AUTH_SMS_COUNTRY_NOT_ALLOWED: 'AUTH_SMS_COUNTRY_NOT_ALLOWED',
|
|
76
|
+
AUTH_SMS_RATE_LIMITED: 'AUTH_SMS_RATE_LIMITED',
|
|
77
|
+
AUTH_SMS_NUMBER_BLOCKED: 'AUTH_SMS_NUMBER_BLOCKED',
|
|
78
|
+
AUTH_SMS_PROJECT_SUSPENDED: 'AUTH_SMS_PROJECT_SUSPENDED',
|
|
79
|
+
AUTH_SMS_CODE_INVALID: 'AUTH_SMS_CODE_INVALID',
|
|
80
|
+
// デプロイするソースの受け渡し(CLI → Control Plane)
|
|
81
|
+
/** compute を宣言しているのにソースが届いていない */
|
|
82
|
+
SOURCE_REQUIRED: 'SOURCE_REQUIRED',
|
|
83
|
+
/** 送られたソースが上限を超えた */
|
|
84
|
+
SOURCE_TOO_LARGE: 'SOURCE_TOO_LARGE',
|
|
85
|
+
/** アーカイブが壊れている、または受け付けない内容を含む */
|
|
86
|
+
SOURCE_INVALID_ARCHIVE: 'SOURCE_INVALID_ARCHIVE',
|
|
87
|
+
/** sourceId が見つからない(期限切れ、または既に使い終わっている) */
|
|
88
|
+
SOURCE_NOT_FOUND: 'SOURCE_NOT_FOUND',
|
|
89
|
+
// Compute
|
|
90
|
+
COMPUTE_PUBLIC_URL_UNREACHABLE: 'COMPUTE_PUBLIC_URL_UNREACHABLE',
|
|
91
|
+
COMPUTE_CONTAINER_EXITED: 'COMPUTE_CONTAINER_EXITED',
|
|
92
|
+
COMPUTE_PORT_NOT_PUBLISHED: 'COMPUTE_PORT_NOT_PUBLISHED',
|
|
93
|
+
APPLY_DEPENDENCY_OUTPUTS_MISSING: 'APPLY_DEPENDENCY_OUTPUTS_MISSING',
|
|
94
|
+
// Control Plane API
|
|
95
|
+
API_UNAUTHORIZED: 'API_UNAUTHORIZED',
|
|
96
|
+
ENVIRONMENT_NOT_FOUND: 'ENVIRONMENT_NOT_FOUND',
|
|
97
|
+
API_KEY_NOT_FOUND: 'API_KEY_NOT_FOUND',
|
|
98
|
+
SIGNUP_NOT_READY: 'SIGNUP_NOT_READY',
|
|
99
|
+
SIGNUP_EMAIL_INVALID: 'SIGNUP_EMAIL_INVALID',
|
|
100
|
+
SIGNUP_EMAIL_REJECTED: 'SIGNUP_EMAIL_REJECTED',
|
|
101
|
+
// 課金
|
|
102
|
+
ORG_SPEND_LIMIT_EXCEEDED: 'ORG_SPEND_LIMIT_EXCEEDED',
|
|
103
|
+
ORG_PROJECT_LIMIT_REACHED: 'ORG_PROJECT_LIMIT_REACHED',
|
|
104
|
+
/** Free プランでは使えない操作。カード登録(Pro)で解ける */
|
|
105
|
+
BILLING_REQUIRED: 'BILLING_REQUIRED',
|
|
106
|
+
BILLING_ALREADY_ACTIVE: 'BILLING_ALREADY_ACTIVE',
|
|
107
|
+
/** Pro → Free に戻り、残すプロジェクトを選ぶまでデプロイできない */
|
|
108
|
+
PROJECT_SELECTION_REQUIRED: 'PROJECT_SELECTION_REQUIRED',
|
|
109
|
+
// プロバイダ
|
|
110
|
+
PROVIDER_UNEXPECTED_ERROR: 'PROVIDER_UNEXPECTED_ERROR',
|
|
111
|
+
};
|
|
112
|
+
// --- suggestedFix つきファクトリ ---------------------------------------------
|
|
113
|
+
export function destructiveChangeBlocked(changeKeys) {
|
|
114
|
+
return new SuperzeroError({
|
|
115
|
+
code: ErrorCode.PLAN_DESTRUCTIVE_CHANGE_BLOCKED,
|
|
116
|
+
message: `This plan contains destructive changes that would delete data: ${changeKeys.join(', ')}. ` +
|
|
117
|
+
`They were not applied.`,
|
|
118
|
+
suggestedFix: {
|
|
119
|
+
description: 'Review the listed resources. If the deletion is intended, re-run apply with --allow-destructive. ' +
|
|
120
|
+
'If not, restore the removed entries in superzero.config.ts.',
|
|
121
|
+
command: 'superzero apply --allow-destructive',
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Control Plane API のトークンが無い・違う。
|
|
127
|
+
*
|
|
128
|
+
* ★ 「無い」と「違う」を区別しない。区別すると、トークンの存在自体が
|
|
129
|
+
* 総当たりの手がかりになる。エージェントにとっては、どちらでも次の行動は同じ。
|
|
130
|
+
*/
|
|
131
|
+
export function apiUnauthorized() {
|
|
132
|
+
return new SuperzeroError({
|
|
133
|
+
code: ErrorCode.API_UNAUTHORIZED,
|
|
134
|
+
message: 'The request did not carry a valid Control Plane API token.',
|
|
135
|
+
suggestedFix: {
|
|
136
|
+
description: 'Set SUPERZERO_TOKEN to the same value as SUPERZERO_API_TOKEN on the control plane, ' +
|
|
137
|
+
'then run the command again. Do not put the token in superzero.config.ts.',
|
|
138
|
+
command: 'export SUPERZERO_TOKEN=...',
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
export function missingDependency(changeKey, missing) {
|
|
143
|
+
return new SuperzeroError({
|
|
144
|
+
code: ErrorCode.PLAN_MISSING_DEPENDENCY,
|
|
145
|
+
message: `Resource "${changeKey}" depends on "${missing}", which is not declared in superzero.config.ts.`,
|
|
146
|
+
suggestedFix: {
|
|
147
|
+
description: `Declare "${missing}" in superzero.config.ts, or remove it from the dependent resource's envFrom.`,
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
export function circularDependency(cycle) {
|
|
152
|
+
return new SuperzeroError({
|
|
153
|
+
code: ErrorCode.PLAN_CIRCULAR_DEPENDENCY,
|
|
154
|
+
message: `Circular dependency between resources: ${cycle.join(' -> ')}.`,
|
|
155
|
+
suggestedFix: {
|
|
156
|
+
description: 'Break the cycle by removing one of the envFrom references in superzero.config.ts.',
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
export function secretNotFound(key) {
|
|
161
|
+
return new SuperzeroError({
|
|
162
|
+
code: ErrorCode.SECRET_NOT_FOUND,
|
|
163
|
+
message: `Secret "${key}" is referenced in superzero.config.ts but has not been set.`,
|
|
164
|
+
suggestedFix: {
|
|
165
|
+
description: `Set the secret, then apply again.`,
|
|
166
|
+
command: `superzero secrets set ${key} <value>`,
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/** 濫用防止の第1層。設定漏れで全開放にならないよう、必ずこのエラーで止める */
|
|
171
|
+
export function smsCountryNotAllowed(countryCode, allowed) {
|
|
172
|
+
return new SuperzeroError({
|
|
173
|
+
code: ErrorCode.AUTH_SMS_COUNTRY_NOT_ALLOWED,
|
|
174
|
+
message: `SMS to country code ${countryCode} is not allowed. ` +
|
|
175
|
+
`Only [${allowed.join(', ')}] is permitted for this project.`,
|
|
176
|
+
suggestedFix: {
|
|
177
|
+
description: `Add "${countryCode}" to auth.sms.allowedCountries in superzero.config.ts, then run apply.`,
|
|
178
|
+
configPatch: { auth: { sms: { allowedCountries: [...allowed, countryCode] } } },
|
|
179
|
+
command: 'superzero apply',
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* コンテナが起動直後に終了した。
|
|
185
|
+
* 起動コマンドの誤り、必須の環境変数の欠落、ビルド成果物の不備などで日常的に起きる。
|
|
186
|
+
* 生の例外にせず、エージェントが次に何を見るべきかまで示す。
|
|
187
|
+
*/
|
|
188
|
+
/**
|
|
189
|
+
* 公開URLに外から到達できない。
|
|
190
|
+
*
|
|
191
|
+
* ★ 内部疎通が緑でもここが赤なら、利用者からは何も見えない。
|
|
192
|
+
* 原因は DNS・証明書・Caddy のルーティングのいずれかで、
|
|
193
|
+
* どれもコンテナの中を見ても分からない。切り分けの起点を示す。
|
|
194
|
+
*/
|
|
195
|
+
export function publicUrlUnreachable(url, reason) {
|
|
196
|
+
return new SuperzeroError({
|
|
197
|
+
code: ErrorCode.COMPUTE_PUBLIC_URL_UNREACHABLE,
|
|
198
|
+
message: `The application answers internally, but ${url} could not be reached from outside ` +
|
|
199
|
+
`(${reason}). Users cannot see this deployment.`,
|
|
200
|
+
suggestedFix: {
|
|
201
|
+
description: 'The container is fine; the path to it is not. Check, in this order: ' +
|
|
202
|
+
'(1) the domain resolves to this host, including the wildcard record; ' +
|
|
203
|
+
'(2) ports 80 and 443 are open to the internet, which certificate issuance needs; ' +
|
|
204
|
+
'(3) the edge server obtained a certificate for this hostname.',
|
|
205
|
+
command: 'superzero status',
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
export function containerExited(containerId) {
|
|
210
|
+
return new SuperzeroError({
|
|
211
|
+
code: ErrorCode.COMPUTE_CONTAINER_EXITED,
|
|
212
|
+
message: `The container started but exited immediately (id: ${containerId.slice(0, 12)}). ` +
|
|
213
|
+
`The application is not running, so it has no reachable address.`,
|
|
214
|
+
cause: { provider: 'docker', raw: { containerId } },
|
|
215
|
+
suggestedFix: {
|
|
216
|
+
description: 'Read the container logs to see why the process exited. ' +
|
|
217
|
+
'The usual causes are a wrong start command, a missing required environment variable, ' +
|
|
218
|
+
'or a build that produced no runnable entrypoint. ' +
|
|
219
|
+
'Set compute.startCommand in superzero.config.ts if the framework was detected incorrectly.',
|
|
220
|
+
command: 'superzero logs',
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* コンテナは起動したが、ホストへのポート公開が完了しなかった。
|
|
226
|
+
*
|
|
227
|
+
* Docker は start の応答後に非同期でポートを割り当てるため、
|
|
228
|
+
* 起動直後の inspect では必ず空に見える(実機で確認済み)。
|
|
229
|
+
* 待っても現れない場合はポートの枯渇か bind の失敗を疑う。
|
|
230
|
+
*/
|
|
231
|
+
export function portNotPublished(containerId, containerPort, published) {
|
|
232
|
+
return new SuperzeroError({
|
|
233
|
+
code: ErrorCode.COMPUTE_PORT_NOT_PUBLISHED,
|
|
234
|
+
message: `The container is running but Docker never published a host port` +
|
|
235
|
+
`${containerPort ? ` for ${containerPort}/tcp` : ''} (id: ${containerId.slice(0, 12)}).`,
|
|
236
|
+
cause: { provider: 'docker', raw: { containerId, published } },
|
|
237
|
+
suggestedFix: {
|
|
238
|
+
description: 'This usually means the host has run out of free ports, or too many containers are ' +
|
|
239
|
+
'running. Remove unused deployments and try again. If it persists, the Docker daemon ' +
|
|
240
|
+
'may need a restart.',
|
|
241
|
+
command: 'superzero status',
|
|
242
|
+
},
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
// --- デプロイするソース -------------------------------------------------------
|
|
246
|
+
/**
|
|
247
|
+
* compute を宣言しているのに、ビルドするソースが届いていない。
|
|
248
|
+
*
|
|
249
|
+
* ★ ここを黙って通してはいけない。
|
|
250
|
+
* ソースが読めないと plan は「変更なし」と答え、コードを直したのに
|
|
251
|
+
* 古いコンテナが動き続ける。エージェントからは成功に見える。
|
|
252
|
+
*/
|
|
253
|
+
export function sourceRequired() {
|
|
254
|
+
return new SuperzeroError({
|
|
255
|
+
code: ErrorCode.SOURCE_REQUIRED,
|
|
256
|
+
message: 'superzero.config.ts declares a compute block, but no application source reached the ' +
|
|
257
|
+
'control plane, so there is nothing to build.',
|
|
258
|
+
suggestedFix: {
|
|
259
|
+
description: 'Run the command from the directory that holds superzero.config.ts so the CLI can pack ' +
|
|
260
|
+
'and upload the project. If this project has no application to deploy, remove the ' +
|
|
261
|
+
'compute block from superzero.config.ts.',
|
|
262
|
+
command: 'superzero apply',
|
|
263
|
+
},
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
/** 送られたソースが上限を超えた。何が超えたかを具体的に言う */
|
|
267
|
+
export function sourceTooLarge(actual, limit) {
|
|
268
|
+
return new SuperzeroError({
|
|
269
|
+
code: ErrorCode.SOURCE_TOO_LARGE,
|
|
270
|
+
message: `The project source is too large to deploy: ${actual} (the limit is ${limit}).`,
|
|
271
|
+
suggestedFix: {
|
|
272
|
+
description: 'Build artifacts, datasets and media are the usual cause. Add them to .gitignore — ' +
|
|
273
|
+
'the CLI does not upload anything git ignores. Directories named node_modules, dist, ' +
|
|
274
|
+
'build, .next, .turbo, target, __pycache__ and .venv are always skipped.',
|
|
275
|
+
command: 'superzero apply',
|
|
276
|
+
},
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* アーカイブが壊れている、または受け付けない内容を含む。
|
|
281
|
+
*
|
|
282
|
+
* ★ 理由を必ず載せる。「不正です」だけだと、送り直す以外の行動が取れない。
|
|
283
|
+
*/
|
|
284
|
+
export function sourceInvalidArchive(reason) {
|
|
285
|
+
return new SuperzeroError({
|
|
286
|
+
code: ErrorCode.SOURCE_INVALID_ARCHIVE,
|
|
287
|
+
message: `The uploaded project source could not be read: ${reason}.`,
|
|
288
|
+
suggestedFix: {
|
|
289
|
+
description: 'The control plane only accepts archives produced by the Superzero CLI, containing ' +
|
|
290
|
+
'regular files under the project directory. Symlinks, device nodes and paths that ' +
|
|
291
|
+
'point outside the project are rejected. If you did run the CLI, the upload was most ' +
|
|
292
|
+
'likely damaged in transit — run the command again, and update the CLI if it persists.',
|
|
293
|
+
command: 'superzero apply',
|
|
294
|
+
},
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
/** sourceId が見つからない。期限切れか、既に使い終わっている */
|
|
298
|
+
export function sourceNotFound(sourceId) {
|
|
299
|
+
return new SuperzeroError({
|
|
300
|
+
code: ErrorCode.SOURCE_NOT_FOUND,
|
|
301
|
+
message: `The uploaded source "${sourceId}" is no longer available on the control plane.`,
|
|
302
|
+
suggestedFix: {
|
|
303
|
+
description: 'Uploaded sources are kept only for the deployment that follows them, and are discarded ' +
|
|
304
|
+
'after a short while. Run the command again; the CLI uploads the project each time.',
|
|
305
|
+
command: 'superzero apply',
|
|
306
|
+
},
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA0BH,MAAM,SAAS,GAAG,8BAA8B,CAAA;AAWhD,MAAM,OAAO,cAAe,SAAQ,KAAK;IAC9B,IAAI,CAAQ;IACZ,aAAa,CAAwB;IACrC,YAAY,CAA0B;IACtC,OAAO,CAAQ;IAExB,YAAY,IAAwB;QAClC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACnB,IAAI,CAAC,IA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