LuvDaSun / SkiffaGenerator

ISC License
3 stars 2 forks source link

Improve error in case of invalid specification #100

Open mgm1313 opened 2 months ago

mgm1313 commented 2 months ago

Edit: I found out the issue is within my specification. If I paste an example YAML, the build does work. Would be nice if the error message was more specific on this!

I'm creating a proof of concept for using Skiffa in our Buchung monorepo. I followed the examples as closely as possible, but the skiffa-generator throws an error.

initialize.js:

#!/usr/bin/env node
import { execFileSync } from "child_process";
import path from "path";
import { fileURLToPath } from "url";

const dirname = path.dirname(fileURLToPath(import.meta.url));
const workspaceRoot = path.resolve(dirname, "..");

const options = { shell: true, stdio: "inherit", env: process.env };

execFileSync(
  "pnpm",
  [
    "--package",
    "@skiffa/generator@0.13.17",
    "dlx",
    "skiffa-generator",
    "package",
    path.resolve(workspaceRoot, "specifications", "api.yaml"),
    "--package-directory",
    path.resolve(workspaceRoot, "generated", "sdk"),
    "--package-name",
    "@buchungapp/sdk",
    "--package-version",
    "0.1.0",
  ],
  options,
);

execFileSync("pnpm", ["--filter", "@buchungapp/sdk", "install"], options);
execFileSync("pnpm", ["--filter", "@buchungapp/sdk", "build"], options);
> node scripts/initialize.js

program.js package [specification-location]

create package from specification location

Positionals:
  specification-location  url to download specification from            [string]

Options:
  --help                          Show help                            [boolean]
  --version                       Show version number                  [boolean]
  --package-directory             where to output the package[string] [required]
  --package-name                  name of the package        [string] [required]
  --package-version               version of the package     [string] [required]
  --default-type-name             default name for types
                                                    [string] [default: "schema"]
  --transform-maximum-iterations  maximum number of iterations for transforming
                                                        [number] [default: 1000]
  --request-types                 Preferred request content-types
      [array] [default: ["application/json","multipart/form-data","text/plain"]]
  --response-types                Preferred response content-types
  [array] [default: ["application/x-ndjson","application/json","multipart/form-d
                                                             ata","text/plain"]]
  --base-url                      The default location from where the api is
                                  served                                [string]

6
node:internal/errors:983
  const err = new Error(message);
              ^

Error: Command failed: pnpm --package @skiffa/generator@0.13.17 dlx skiffa-generator package /Users/techmaus/code/MijnZeilschool/buchung/specifications/api.yaml --package-directory /Users/techmaus/code/MijnZeilschool/buchung/generated/sdk --package-name @buchungapp/sdk --package-version 0.1.0
    at genericNodeError (node:internal/errors:983:15)
    at wrappedFn (node:internal/errors:537:14)
    at checkExecSyncError (node:child_process:890:11)
    at execFileSync (node:child_process:926:15)
    at file:///Users/techmaus/code/MijnZeilschool/buchung/scripts/initialize.js:11:1
    at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:483:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 79912,
  stdout: null,
  stderr: null
}

Node.js v22.9.0
 ELIFECYCLE  Command failed with exit code 1.

I'm having trouble because the error message isn't very helpful. I'm not sure what's going wrong.