badgr-cli 1.0.6 → 1.0.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badgr-cli",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Badgr — run or serve GPU workloads from one command",
5
5
  "type": "module",
6
6
  "bin": {
package/src/api.js CHANGED
@@ -48,21 +48,28 @@ export async function callApi(path, { method = 'GET', apiKey, baseUrl, body } =
48
48
  if (!res.ok) {
49
49
  let detail = '';
50
50
  let rawBody = '';
51
+ let errorData = null;
51
52
  try {
52
53
  rawBody = await res.text();
53
54
  dbg('Error response body:', rawBody);
54
55
  const json = JSON.parse(rawBody);
56
+ errorData = json;
55
57
  detail = json?.detail ?? json?.message ?? json?.error ?? rawBody;
56
58
  } catch {
57
59
  detail = rawBody || res.statusText || '';
58
60
  }
61
+ const isCapacityError = errorData?.code === 'NO_CAPACITY_MATCH';
59
62
  const hint =
60
63
  res.status === 401 ? '\n Hint: Invalid or missing API key — run: badgr login' :
61
64
  res.status === 403 ? '\n Hint: Access denied — check your API key permissions' :
62
65
  res.status === 404 ? `\n Hint: Endpoint not found — check BADGR_API_URL (currently: ${baseUrl})` :
63
- res.status === 502 || res.status === 503 ? '\n Hint: Server error — no GPU capacity available or backend is down' :
66
+ (res.status === 502 || res.status === 503) && !isCapacityError
67
+ ? '\n Hint: Server error — no GPU capacity available or backend is down' :
64
68
  '';
65
- throw new Error(`${method} ${path} → HTTP ${res.status}: ${detail}${hint}`);
69
+ const err = new Error(`${method} ${path} → HTTP ${res.status}: ${detail}${hint}`);
70
+ err.errorData = errorData;
71
+ err.httpStatus = res.status;
72
+ throw err;
66
73
  }
67
74
  return res.json();
68
75
  }
@@ -113,16 +113,28 @@ export async function runCommand(config, args, chalk) {
113
113
  image,
114
114
  gpu: gpu.toUpperCase().replace('-', '_'),
115
115
  gpu_count: flags.count || 1,
116
- region: flags.region || 'US',
116
+ ...(flags.region ? { region: flags.region.toUpperCase() } : {}),
117
117
  max_price_per_hour: flags.maxPrice,
118
118
  name: flags.name,
119
119
  },
120
120
  });
121
121
  } catch (err) {
122
- console.error(chalk.red(`\n ✗ Job failed to start: ${err.message}`));
123
- console.error(chalk.dim(`\n Debug: BADGR_DEBUG=1 badgr run … — shows full request/response`));
124
- console.error(chalk.dim(` Config: badgr config`));
125
- console.error(chalk.dim(` Docs: badgr --help\n`));
122
+ const d = err.errorData;
123
+ if (d?.code === 'NO_CAPACITY_MATCH') {
124
+ const f = d.filters ?? {};
125
+ const scope = f.region && f.region !== 'any' ? `in ${f.region}` : 'globally';
126
+ console.error(chalk.red(`\n ✗ No ${f.gpu || gpu} found under ${f.max_price || '$10/hr'} ${scope}.`));
127
+ if (d.suggestions?.length) {
128
+ console.error(chalk.dim(`\n Try:`));
129
+ for (const s of d.suggestions) console.error(chalk.dim(` • ${s}`));
130
+ }
131
+ console.error('');
132
+ } else {
133
+ console.error(chalk.red(`\n ✗ Job failed to start: ${err.message}`));
134
+ console.error(chalk.dim(`\n Debug: BADGR_DEBUG=1 badgr run … — shows full request/response`));
135
+ console.error(chalk.dim(` Config: badgr config`));
136
+ console.error(chalk.dim(` Docs: badgr --help\n`));
137
+ }
126
138
  process.exit(1);
127
139
  }
128
140