Skip to content

Commit e2b27e0

Browse files
author
Raylan LIN
committed
fix(music): add output-format validation, handle missing audio_url, add trailing newline
- Validate --output-format is 'hex' or 'url' before sending to API - Throw CLIError when URL output requested but API returns no audio_url (previously wrote 0-byte empty file silently) - Use console.log for URL output to include trailing newline (W2 fix) - Simplify: quiet mode already gets clean URL, non-quiet gets JSON/text via formatOutput — no need for separate branches
1 parent e364c36 commit e2b27e0

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

src/commands/music/generate.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ export default defineCommand({
126126

127127
const model = (flags.model as string) || musicGenerateModel(config);
128128
const outFormat = (flags.outputFormat as string) || 'hex';
129+
if (outFormat !== 'hex' && outFormat !== 'url') {
130+
throw new CLIError(
131+
'--output-format must be "hex" or "url".',
132+
ExitCode.USAGE,
133+
'mmx music generate --output-format url',
134+
);
135+
}
129136
const body: MusicRequest = {
130137
model,
131138
prompt,
@@ -170,11 +177,14 @@ export default defineCommand({
170177
});
171178

172179
if (!config.quiet) process.stderr.write(`[Model: ${model}]\n`);
173-
if (outFormat === 'url' && response.data?.audio_url) {
174-
if (config.quiet) {
175-
process.stdout.write(response.data.audio_url);
180+
if (outFormat === 'url') {
181+
if (response.data?.audio_url) {
182+
console.log(response.data.audio_url);
176183
} else {
177-
process.stdout.write(formatOutput({ audio_url: response.data.audio_url }, format));
184+
throw new CLIError(
185+
'Requested URL output but API did not return audio_url.',
186+
ExitCode.GENERAL,
187+
);
178188
}
179189
return;
180190
}

0 commit comments

Comments
 (0)