Skip to content
Open
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
4 changes: 3 additions & 1 deletion docs/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ CLIError (abstract base class)
│ ├── ConfigInvalidError # Invalid config syntax/structure
│ ├── ConfigExistsError # Project already exists
│ ├── SchemaValidationError # Zod validation failed
│ └── InvalidInputError # Bad user input (template not found, etc.)
│ ├── InvalidInputError # Bad user input (template not found, etc.)
│ └── DeploymentFailedError # Deploy completed with failed resources
└── SystemError (something broke - needs investigation)
├── ApiError # HTTP/network failures
Expand Down Expand Up @@ -109,6 +110,7 @@ See [api-patterns.md](api-patterns.md) for the full `ApiError.fromHttpError()` p
| `CONFIG_EXISTS` | `ConfigExistsError` | Project already exists at location |
| `SCHEMA_INVALID` | `SchemaValidationError` | Zod validation failed |
| `INVALID_INPUT` | `InvalidInputError` | User provided invalid input |
| `DEPLOYMENT_FAILED` | `DeploymentFailedError` | Deploy completed with failed resources |
| `API_ERROR` | `ApiError` | API request failed |
| `FILE_NOT_FOUND` | `FileNotFoundError` | File doesn't exist |
| `FILE_READ_ERROR` | `FileReadError` | Can't read/write file |
Expand Down
9 changes: 8 additions & 1 deletion packages/cli/src/cli/commands/functions/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Logger } from "@base44-cli/logger";
import type { Command } from "commander";
import { throwIfFunctionDeployFailed } from "@/cli/commands/functions/deployFailures.js";
import { formatDeployResult } from "@/cli/commands/functions/formatDeployResult.js";
import { parseNames } from "@/cli/commands/functions/parseNames.js";
import type { CLIContext, RunCommandResult } from "@/cli/types.js";
Expand Down Expand Up @@ -100,6 +101,12 @@ async function deployFunctionsAction(
},
});

const summary = buildDeploySummary(results);
if (results.some((result) => result.status === "error")) {
log.info(summary);
}
throwIfFunctionDeployFailed(results);

if (options.force) {
const allLocalNames = functions.map((f) => f.name);
let pruneCompleted = 0;
Expand All @@ -126,7 +133,7 @@ async function deployFunctionsAction(
formatPruneSummary(pruneResults, log);
}

return { outroMessage: buildDeploySummary(results) };
return { outroMessage: summary };
}

export function getDeployCommand(): Command {
Expand Down
20 changes: 20 additions & 0 deletions packages/cli/src/cli/commands/functions/deployFailures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { DeploymentFailedError } from "@/core/errors.js";
import type { SingleFunctionDeployResult } from "@/core/resources/function/deploy.js";

function buildFunctionDeployFailureMessage(
results: SingleFunctionDeployResult[],
): string | null {
const failed = results.filter((result) => result.status === "error").length;
if (failed === 0) return null;

return `${failed} ${failed === 1 ? "function" : "functions"} failed to deploy`;
}

export function throwIfFunctionDeployFailed(
results: SingleFunctionDeployResult[],
): void {
const message = buildFunctionDeployFailureMessage(results);
if (message) {
throw new DeploymentFailedError(message);
}
}
3 changes: 3 additions & 0 deletions packages/cli/src/cli/commands/project/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
filterPendingOAuth,
promptOAuthFlows,
} from "@/cli/commands/connectors/oauth-prompt.js";
import { throwIfFunctionDeployFailed } from "@/cli/commands/functions/deployFailures.js";
import { formatDeployResult } from "@/cli/commands/functions/formatDeployResult.js";
import type { CLIContext, RunCommandResult } from "@/cli/types.js";
import {
Expand Down Expand Up @@ -130,6 +131,8 @@ export async function deployAction(
);
}

throwIfFunctionDeployFailed(result.functionResults);

return { outroMessage: "App deployed successfully" };
}

Expand Down
17 changes: 17 additions & 0 deletions packages/cli/src/core/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,23 @@ export class InvalidInputError extends UserError {
readonly code = "INVALID_INPUT";
}

/**
* Thrown when deployment completes with one or more failed resources.
*/
export class DeploymentFailedError extends UserError {
readonly code = "DEPLOYMENT_FAILED";

constructor(message: string, options?: CLIErrorOptions) {
super(message, {
hints: options?.hints ?? [
{ message: "Check the deployment errors above and try again" },
],
details: options?.details,
cause: options?.cause,
});
}
}

/**
* Thrown when a required external dependency is not installed (e.g., Deno, Git).
*/
Expand Down
10 changes: 7 additions & 3 deletions packages/cli/src/core/project/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export function hasResourcesToDeploy(projectData: ProjectData): boolean {
* Result of deploying all project resources.
*/
interface DeployAllResult {
/**
* Per-function deployment results, including any failed functions.
*/
functionResults: SingleFunctionDeployResult[];
/**
* The app URL if a site was deployed, undefined otherwise.
*/
Expand Down Expand Up @@ -73,7 +77,7 @@ export async function deployAll(
projectData;

await entityResource.push(entities);
await deployFunctionsSequentially(functions, {
const functionResults = await deployFunctionsSequentially(functions, {
onStart: options?.onFunctionStart,
onResult: options?.onFunctionResult,
});
Expand All @@ -84,8 +88,8 @@ export async function deployAll(
if (project.site?.outputDirectory) {
const outputDir = resolve(project.root, project.site.outputDirectory);
const { appUrl } = await deploySite(outputDir);
return { appUrl, connectorResults };
return { functionResults, appUrl, connectorResults };
}

return { connectorResults };
return { functionResults, connectorResults };
}
19 changes: 19 additions & 0 deletions packages/cli/tests/cli/deploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ describe("deploy command (unified)", () => {
t.expectResult(result).toContain("App deployed successfully");
});

it("fails when a function deployment fails", async () => {
await t.givenLoggedInWithProject(fixture("with-functions-and-entities"));
t.api.mockEntitiesPush({ created: ["Order"], updated: [], deleted: [] });
t.api.mockSingleFunctionDeployError({
status: 400,
body: { error: "Invalid function code" },
});
t.api.mockAgentsPush({ created: [], updated: [], deleted: [] });
t.api.mockConnectorsList({ integrations: [] });
t.api.mockStripeStatus({ stripe_mode: null });

const result = await t.run("deploy", "-y");

t.expectResult(result).toFail();
t.expectResult(result).toContain("Invalid function code");
t.expectResult(result).toContain("1 function failed to deploy");
t.expectResult(result).toNotContain("App deployed successfully");
});

it("deploys zero-config functions (path-based names) with unified deploy", async () => {
await t.givenLoggedInWithProject(fixture("with-zero-config-functions"));
t.api.mockEntitiesPush({ created: [], updated: [], deleted: [] });
Expand Down
61 changes: 58 additions & 3 deletions packages/cli/tests/cli/functions_deploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ describe("functions deploy command", () => {

const result = await t.run("functions", "deploy");

t.expectResult(result).toSucceed();
t.expectResult(result).toFail();
t.expectResult(result).toContain("error");
t.expectResult(result).toContain("1 error");
t.expectResult(result).toContain("1 function failed to deploy");
});

it("reports validation error from 422 response", async () => {
Expand All @@ -114,11 +115,12 @@ describe("functions deploy command", () => {

const result = await t.run("functions", "deploy");

t.expectResult(result).toSucceed();
t.expectResult(result).toFail();
t.expectResult(result).toContain("error");
t.expectResult(result).toContain(
"Minimum interval for minute-based schedules is 5 minutes.",
);
t.expectResult(result).toContain("1 function failed to deploy");
});

it("reports too-many-functions error from 422 response", async () => {
Expand All @@ -132,11 +134,64 @@ describe("functions deploy command", () => {

const result = await t.run("functions", "deploy");

t.expectResult(result).toSucceed();
t.expectResult(result).toFail();
t.expectResult(result).toContain("error");
t.expectResult(result).toContain(
"Maximum of 50 functions per app reached.",
);
t.expectResult(result).toContain("1 function failed to deploy");
});

it("prunes remote functions missing locally with --force", async () => {
await t.givenLoggedInWithProject(fixture("with-functions-and-entities"));
t.api.mockSingleFunctionDeploy({ status: "deployed" });
t.api.mockFunctionsList({
functions: [
{
name: "stale-function",
deployment_id: "dep_123",
entry: "index.ts",
files: [],
automations: [],
},
],
});
t.api.mockSingleFunctionDelete();

const result = await t.run("functions", "deploy", "--force");

t.expectResult(result).toSucceed();
t.expectResult(result).toContain("Found 1 remote function to delete");
t.expectResult(result).toContain("stale-function");
t.expectResult(result).toContain("deleted");
t.expectResult(result).toContain("1 deleted");
});

it("does not prune remote functions when deploy fails with --force", async () => {
await t.givenLoggedInWithProject(fixture("with-functions-and-entities"));
t.api.mockSingleFunctionDeployError({
status: 400,
body: { error: "Invalid function code" },
});
t.api.mockFunctionsList({
functions: [
{
name: "stale-function",
deployment_id: "dep_123",
entry: "index.ts",
files: [],
automations: [],
},
],
});
t.api.mockSingleFunctionDelete();

const result = await t.run("functions", "deploy", "--force");

t.expectResult(result).toFail();
t.expectResult(result).toContain("1 function failed to deploy");
t.expectResult(result).toNotContain("Found 1 remote function to delete");
t.expectResult(result).toNotContain("stale-function");
});

it("rejects --force with specific function names", async () => {
Expand Down
Loading