|
25 | 25 | import * as http from "http";
|
26 | 26 | import * as express from "express";
|
27 | 27 | import * as fs from "fs/promises";
|
| 28 | +import * as path from "path"; |
28 | 29 | import { loadStack } from "../runtime/loader";
|
29 | 30 | import { stackToWire } from "../runtime/manifest";
|
30 | 31 |
|
@@ -57,20 +58,40 @@ function handleQuitquitquit(req: express.Request, res: express.Response, server:
|
57 | 58 |
|
58 | 59 | if (process.env.FUNCTIONS_MANIFEST_OUTPUT_PATH) {
|
59 | 60 | void (async () => {
|
| 61 | + const outputPath = process.env.FUNCTIONS_MANIFEST_OUTPUT_PATH; |
60 | 62 | try {
|
| 63 | + // Validate the output path |
| 64 | + const dir = path.dirname(outputPath); |
| 65 | + try { |
| 66 | + await fs.access(dir, fs.constants.W_OK); |
| 67 | + } catch (e) { |
| 68 | + console.error( |
| 69 | + `Error: Cannot write to directory '${dir}': ${e instanceof Error ? e.message : String(e)}` |
| 70 | + ); |
| 71 | + console.error("Please ensure the directory exists and you have write permissions."); |
| 72 | + process.exit(1); |
| 73 | + } |
| 74 | + |
61 | 75 | const stack = await loadStack(functionsDir);
|
62 | 76 | const wireFormat = stackToWire(stack);
|
63 |
| - await fs.writeFile( |
64 |
| - process.env.FUNCTIONS_MANIFEST_OUTPUT_PATH, |
65 |
| - JSON.stringify(wireFormat, null, 2) |
66 |
| - ); |
| 77 | + await fs.writeFile(outputPath, JSON.stringify(wireFormat, null, 2)); |
67 | 78 | process.exit(0);
|
68 |
| - } catch (e) { |
69 |
| - console.error( |
70 |
| - `Failed to generate manifest from function source: ${ |
71 |
| - e instanceof Error ? e.message : String(e) |
72 |
| - }` |
73 |
| - ); |
| 79 | + } catch (e: any) { |
| 80 | + if (e.code === "ENOENT") { |
| 81 | + console.error(`Error: Directory '${path.dirname(outputPath)}' does not exist.`); |
| 82 | + console.error("Please create the directory or specify a valid path."); |
| 83 | + } else if (e.code === "EACCES") { |
| 84 | + console.error(`Error: Permission denied writing to '${outputPath}'.`); |
| 85 | + console.error("Please check file permissions or choose a different location."); |
| 86 | + } else if (e.message?.includes("Failed to generate manifest")) { |
| 87 | + console.error(e.message); |
| 88 | + } else { |
| 89 | + console.error( |
| 90 | + `Failed to generate manifest from function source: ${ |
| 91 | + e instanceof Error ? e.message : String(e) |
| 92 | + }` |
| 93 | + ); |
| 94 | + } |
74 | 95 | if (e instanceof Error && e.stack) {
|
75 | 96 | console.error(e.stack);
|
76 | 97 | }
|
|
0 commit comments