Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/dev/codezip.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe("CodeZipDevRunner", () => {
tempDirectories.push(root);

await expect(collect(harness().runner.run(input(root, runtime())))).rejects.toThrow(
/runtime code directory not found/,
/no runtime code directory exists at/,
);
});

Expand Down
6 changes: 3 additions & 3 deletions src/core/dev/codezip.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { existsSync } from "node:fs";
import { delimiter, join, resolve } from "node:path";
import { InputValidationError } from "../../errors";
import { ResourceNotFoundError } from "../../errors";
import type { DevEvent, DevRunner, DevServerInput } from "../../handlers/project/dev/types";
import {
runProcess,
Expand Down Expand Up @@ -32,7 +32,7 @@ export class CodeZipDevRunner implements DevRunner {
public async *run(input: DevServerInput): AsyncGenerator<DevEvent, void> {
const directory = resolve(input.projectRoot, input.runtime.codeLocation);
if (!isDirectory(directory)) {
throw new InputValidationError(`runtime code directory not found: ${directory}`);
throw new ResourceNotFoundError(`no runtime code directory exists at ${directory}`);
}
resolvePathWithinProject(input.projectRoot, directory, "runtime code directory");

Expand All @@ -46,7 +46,7 @@ export class CodeZipDevRunner implements DevRunner {
: entrypoint!;
const entrypointPath = resolve(directory, devEntrypoint);
if (!isFile(entrypointPath)) {
throw new InputValidationError(`runtime entrypoint not found: ${entrypointPath}`);
throw new ResourceNotFoundError(`no runtime entrypoint exists at ${entrypointPath}`);
}
resolvePathWithinProject(input.projectRoot, entrypointPath, "runtime entrypoint");

Expand Down
10 changes: 5 additions & 5 deletions src/core/dev/container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { mkdir, mkdtemp, readFile, rm, stat, symlink, writeFile } from "node:fs/
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { parseEnv } from "node:util";
import { InputValidationError, InvalidEnvironmentError } from "../../errors";
import { InputValidationError, InvalidEnvironmentError, ResourceNotFoundError } from "../../errors";
import type { DevEvent, DevServerInput } from "../../handlers/project/dev/types";
import {
MissingToolError,
Expand Down Expand Up @@ -518,8 +518,8 @@ describe("ContainerDevRunner", () => {

const promise = collect(runner.run(input(root, runtime())));

await expect(promise).rejects.toBeInstanceOf(InputValidationError);
await expect(promise).rejects.toThrow(/build context directory not found/);
await expect(promise).rejects.toBeInstanceOf(ResourceNotFoundError);
await expect(promise).rejects.toThrow(/no container build context directory exists at/);
expect(probes).toHaveLength(0);
expect(calls).toHaveLength(0);
});
Expand All @@ -539,8 +539,8 @@ describe("ContainerDevRunner", () => {

const promise = collect(runner.run(input(root, projectRuntime)));

await expect(promise).rejects.toBeInstanceOf(InputValidationError);
await expect(promise).rejects.toThrow(/Dockerfile not found/);
await expect(promise).rejects.toBeInstanceOf(ResourceNotFoundError);
await expect(promise).rejects.toThrow(/no container Dockerfile exists at/);
expect(probes).toHaveLength(0);
expect(calls).toHaveLength(0);
});
Expand Down
6 changes: 3 additions & 3 deletions src/core/dev/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { existsSync, writeFileSync } from "node:fs";
import { rm, writeFile } from "node:fs/promises";
import { homedir, tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { InputValidationError, InvalidEnvironmentError } from "../../errors";
import { InputValidationError, InvalidEnvironmentError, ResourceNotFoundError } from "../../errors";
import type { DevEvent, DevRunner, DevServerInput } from "../../handlers/project/dev/types";
import {
MissingToolError,
Expand Down Expand Up @@ -80,15 +80,15 @@ export class ContainerDevRunner implements DevRunner {
input.runtime.buildContextPath ?? input.runtime.codeLocation,
);
if (!isDirectory(context)) {
throw new InputValidationError(`container build context directory not found: ${context}`);
throw new ResourceNotFoundError(`no container build context directory exists at ${context}`);
}

resolvePathWithinProject(input.projectRoot, context, "container build context");

const dockerfile = input.runtime.dockerfile ?? DOCKERFILE_NAME;
const dockerfilePath = join(context, dockerfile);
if (!isFile(dockerfilePath)) {
throw new InputValidationError(`container Dockerfile not found: ${dockerfilePath}`);
throw new ResourceNotFoundError(`no container Dockerfile exists at ${dockerfilePath}`);
}

const hasAwsCredentials = Boolean(
Expand Down
2 changes: 1 addition & 1 deletion src/core/eval.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1961,7 +1961,7 @@ async function resolveAgentToNameAndId(
return harnessRuntimeFromResponse(agent, harness);
} catch (error) {
if (!(error instanceof InputValidationError)) throw error;
throw new InputValidationError(`"${agent}" does not exist as a runtime or a harness`, {
throw new ResourceNotFoundError(`no runtime or harness named '${agent}' exists`, {
cause: error,
meta: { agent },
});
Expand Down
10 changes: 7 additions & 3 deletions src/core/project/bedrockAgentImport/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import {
type AgentActionGroup,
type AgentVersion,
} from "@aws-sdk/client-bedrock-agent";
import { InputValidationError, MalformedServiceResponseError } from "../../../errors";
import {
InputValidationError,
MalformedServiceResponseError,
ResourceNotFoundError,
} from "../../../errors";
import type {
BedrockAgentImportNote,
BedrockAgentSnapshot,
Expand Down Expand Up @@ -140,8 +144,8 @@ export class BedrockAgentSnapshotLoader {
));
} catch (error) {
if (isNamedError(error, "ResourceNotFoundException")) {
throw new InputValidationError(
`Bedrock Agent '${input.agentId}' has no version '${input.agentVersion}' in ${input.region}`,
throw new ResourceNotFoundError(
`no version '${input.agentVersion}' exists for Bedrock Agent '${input.agentId}' in ${input.region}`,
{ cause: error },
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/project/manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ describe("FsProjectManager.create", () => {
dockerfile,
},
}),
).rejects.toThrow(`dockerfile not found: '${dockerfile}'`);
).rejects.toThrow(`no dockerfile exists at ${dockerfile}`);

expect(existsSync(join(directory, "example"))).toBe(false);
});
Expand Down
16 changes: 8 additions & 8 deletions src/core/project/manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ export class FsProjectManager implements ProjectManager {
(candidate) => candidate.name === input.managerName,
);
if (!manager) {
throw new InputValidationError(
`payment manager '${input.managerName}' does not exist in this project`,
throw new ResourceNotFoundError(
`no payment-manager named '${input.managerName}' exists in this project`,
);
}
if (manager.connectors.some((connector) => connector.name === input.resourceConfig.name)) {
Expand Down Expand Up @@ -432,8 +432,8 @@ export class FsProjectManager implements ProjectManager {
(candidate) => candidate.name === gatewayName,
);
if (!gateway) {
throw new InputValidationError(
`gateway '${gatewayName}' does not exist in this project; check agentCoreGateways in agentcore.json`,
throw new ResourceNotFoundError(
`no gateway named '${gatewayName}' exists in this project`,
);
}
gateway.policyEngineConfiguration = {
Expand All @@ -448,8 +448,8 @@ export class FsProjectManager implements ProjectManager {
(candidate) => candidate.name === input.engineName,
);
if (!engine) {
throw new InputValidationError(
`policy engine '${input.engineName}' does not exist in this project; check policyEngines in agentcore.json`,
throw new ResourceNotFoundError(
`no policy-engine named '${input.engineName}' exists in this project`,
);
}
engine.policies.push(parseResource(PolicySchema, input.resourceConfig));
Expand All @@ -460,8 +460,8 @@ export class FsProjectManager implements ProjectManager {
(gateway) => gateway.name === input.gatewayName,
);
if (gatewayIndex < 0) {
throw new InputValidationError(
`gateway '${input.gatewayName}' does not exist in this project; check agentCoreGateways in agentcore.json`,
throw new ResourceNotFoundError(
`no gateway named '${input.gatewayName}' exists in this project`,
);
}
projectSpec.agentCoreGateways[gatewayIndex]!.targets.push(input.resourceConfig);
Expand Down
4 changes: 2 additions & 2 deletions src/core/project/templates/fsTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mkdir, readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import type { AssetSource } from "../source";
import { AgentCoreCLIError, ERROR_SOURCE } from "../../../errors";
import { InputValidationError, ProjectStateError } from "../../../errors/errors";
import { ProjectStateError, ResourceNotFoundError } from "../../../errors/errors";

/**
* FsTreeNode represents a tree of directories and files.
Expand Down Expand Up @@ -64,7 +64,7 @@ export class FsTreeNode {
static fromTextFile(name: string, sourcePath: string): FsTreeNode {
return FsTreeNode.createFile(name, async () => {
if (!existsSync(sourcePath)) {
throw new InputValidationError(`file not found: '${sourcePath}'`);
throw new ResourceNotFoundError(`no source file exists at ${sourcePath}`);
}
return readFile(sourcePath, "utf-8");
});
Expand Down
4 changes: 2 additions & 2 deletions src/core/project/templates/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { existsSync } from "node:fs";
import { ZodError, z } from "zod";
import { HarnessSpecSchema } from "../../../projectSchemas/harness";
import { FsTreeNode } from "./fsTree";
import { InputValidationError } from "../../../errors/errors";
import { InputValidationError, ResourceNotFoundError } from "../../../errors/errors";
import type { TemplateResolver } from "./types";

const DEFAULT_SYSTEM_PROMPT = "You are a helpful assistant";
Expand Down Expand Up @@ -43,7 +43,7 @@ export function getHarnessTemplateResolver(): TemplateResolver<z.input<typeof Ha

export function validateHarnessTemplateSource(spec: z.input<typeof HarnessSpecSchema>): void {
if (spec.dockerfile && !existsSync(spec.dockerfile)) {
throw new InputValidationError(`dockerfile not found: '${spec.dockerfile}'`);
throw new ResourceNotFoundError(`no dockerfile exists at ${spec.dockerfile}`);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/handlers/project/add/gateway-target/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ describe("project add gateway-target", () => {
[
"unknown credential",
endpointFlags("--outbound-auth", "oauth", "--credential-name", "missing"),
"does not exist in credentials[]",
"no credential named 'missing' exists in this project",
],
[
"credential with wrong type",
Expand All @@ -326,7 +326,7 @@ describe("project add gateway-target", () => {
[
"unknown Gateway",
["--gateway", "missing", "--name", "target", "--endpoint", ENDPOINT],
"does not exist in this project; check agentCoreGateways in agentcore.json",
"no gateway named 'missing' exists in this project",
],
])("rejects %s", async (_label, flags, message) => {
await projectWithCredentials();
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/project/add/gateway-target/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import z from "zod";
import { InputValidationError } from "../../../../errors";
import { InputValidationError, ResourceNotFoundError } from "../../../../errors";
import { SourceResolver } from "../../../../io";
import type { Credential } from "../../../../projectSchemas/credential";
import {
Expand Down Expand Up @@ -180,7 +180,7 @@ function validateTargetCredential(project: Project, target: AgentCoreGatewayTarg
function requireCredential(project: Project, name: string): Credential {
const credential = project.spec.credentials.find((candidate) => candidate.name === name);
if (!credential) {
throw new InputValidationError(`credential '${name}' does not exist in credentials[]`);
throw new ResourceNotFoundError(`no credential named '${name}' exists in this project`);
}
return credential;
}
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/project/add/gateway/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ describe("project add gateway", () => {
"--policy-engine-mode",
"enforce",
],
"does not exist in policyEngines[]",
"no policy-engine named 'Missing' exists in this project",
],
[
"CUSTOM_JWT without configuration",
Expand Down
6 changes: 3 additions & 3 deletions src/handlers/project/add/gateway/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import z from "zod";
import { InputValidationError } from "../../../../errors";
import { InputValidationError, ResourceNotFoundError } from "../../../../errors";
import { SourceResolver } from "../../../../io";
import { GatewayAuthorizerConfigSchema } from "../../../../projectSchemas/auth";
import type { AgentCoreGateway } from "../../../../projectSchemas/gateway";
Expand Down Expand Up @@ -84,8 +84,8 @@ export const createAddGatewayHandler = (config: AddProjectResourceConfig) =>
flags["policy-engine-name"] &&
!project.spec.policyEngines.some((engine) => engine.name === flags["policy-engine-name"])
) {
throw new InputValidationError(
`policy engine '${flags["policy-engine-name"]}' does not exist in policyEngines[]`,
throw new ResourceNotFoundError(
`no policy-engine named '${flags["policy-engine-name"]}' exists in this project`,
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/handlers/project/add/payment-connector/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe("project add payment-connector", () => {
"connector",
"--quick-create",
]),
).rejects.toThrow("does not exist");
).rejects.toThrow("no payment-manager named 'missing' exists in this project");
await expect(
run([
"add",
Expand All @@ -119,7 +119,7 @@ describe("project add payment-connector", () => {
"--credential",
"missing",
]),
).rejects.toThrow("does not exist in credentials[]");
).rejects.toThrow("no credential named 'missing' exists in this project");

expect((await projectSpec(projectRoot)).payments[0].connectors).toEqual([]);
});
Expand Down
6 changes: 3 additions & 3 deletions src/handlers/project/add/payment-connector/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import z from "zod";
import { InputValidationError } from "../../../../errors";
import { InputValidationError, ResourceNotFoundError } from "../../../../errors";
import { createHandler, flag, ProjectKey } from "../../../../router";
import type { AddProjectResourceConfig } from "../types";
import { addProjectResource } from "../shared";
Expand Down Expand Up @@ -37,8 +37,8 @@ export const createAddPaymentConnectorHandler = (config: AddProjectResourceConfi
(candidate) => candidate.name === credentialName,
);
if (!credential) {
throw new InputValidationError(
`credential '${credentialName}' does not exist in credentials[]`,
throw new ResourceNotFoundError(
`no credential named '${credentialName}' exists in this project`,
);
}
if (credential.authorizerType !== "PaymentCredentialProvider") {
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/project/add/policy-engine/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe("project add policy-engine", () => {
const projectRoot = await inProject();
await expect(
run(["add", "policy-engine", "--name", "Guardrails", "--attach-to-gateways", "missing"]),
).rejects.toThrow("gateway 'missing' does not exist");
).rejects.toThrow("no gateway named 'missing' exists in this project");
expect((await projectSpec(projectRoot)).policyEngines ?? []).toEqual([]);
});

Expand Down
2 changes: 1 addition & 1 deletion src/handlers/project/add/policy/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe("project add policy", () => {
[
"unknown engine",
["add", "policy", "--engine", "Missing", "--name", "P", "--statement", FORBID_ALL],
"policy engine 'Missing' does not exist",
"no policy-engine named 'Missing' exists in this project",
],
])("rejects %s", async (_label, args, message) => {
await withEngine();
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/project/export/harness.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import z from "zod";
import { InputValidationError } from "../../../errors";
import { InputValidationError, ResourceNotFoundError } from "../../../errors";
import { createHandler, flag, ProjectKey } from "../../../router";
import { JsonRendererKey } from "../../../tui";
import { JsonKey } from "../../keys";
Expand Down Expand Up @@ -45,7 +45,7 @@ export const createExportHarnessHandler = (config: ExportProjectResourceConfig)
const region = regionFromHarnessArn(flags.arn);
const response = await config.core.harness.getHarness(harnessId, { ...coreOpts, region });
if (!response.harness) {
throw new InputValidationError(`the service returned no harness for "${flags.arn}"`);
throw new ResourceNotFoundError(`no harness exists for '${flags.arn}'`);
}
const { spec, systemPrompt, notes } = mapServiceHarnessToSpec(response.harness);
input = {
Expand Down
Loading