edf2csv 0.8.10 → 0.8.12

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.
@@ -351,7 +351,7 @@ async function prepareOutputDir(dir, force) {
351
351
  if (info && !info.isDirectory()) {
352
352
  throw new ConversionError('OUTPUT_UNWRITABLE', `Cannot create "${dir}": "${parent}" is a file, not a directory.`, 'Choose a destination whose parent directories are directories, with --out.');
353
353
  }
354
- throw new ConversionError('OUTPUT_UNWRITABLE', `Cannot create "${dir}": ${describeFsError(cause)}.`, 'Check the path exists and that you have permission to write there.');
354
+ throw new ConversionError('OUTPUT_UNWRITABLE', `Cannot create "${dir}": ${describeFsError(cause)}.`, createHint(cause));
355
355
  }
356
356
  }
357
357
  let claimed = true;
@@ -360,7 +360,7 @@ async function prepareOutputDir(dir, force) {
360
360
  }
361
361
  catch (cause) {
362
362
  if (cause.code !== 'EEXIST') {
363
- throw new ConversionError('OUTPUT_UNWRITABLE', `Cannot create "${dir}": ${describeFsError(cause)}.`, 'Check the path exists and that you have permission to write there.');
363
+ throw new ConversionError('OUTPUT_UNWRITABLE', `Cannot create "${dir}": ${describeFsError(cause)}.`, createHint(cause));
364
364
  }
365
365
  claimed = false;
366
366
  }
@@ -1204,31 +1204,53 @@ function writeHint(cause, toStdout = false) {
1204
1204
  const preamble = toStdout
1205
1205
  ? 'What reached stdout before it failed is incomplete and should not be used. '
1206
1206
  : 'The files written so far are incomplete and should not be used. ';
1207
- const elsewhere = toStdout ? 'redirect it somewhere else' : 'choose another with --out';
1207
+ return (preamble +
1208
+ destinationAdvice(cause, toStdout ? 'redirect it somewhere else' : 'choose another with --out', toStdout ? 'redirect it somewhere shorter' : 'choose a shorter destination with --out'));
1209
+ }
1210
+ /**
1211
+ * The same question asked before anything has been written: the output directory could not be
1212
+ * created.
1213
+ *
1214
+ * Both raisings carried one sentence for every errno — "Check the path exists and that you
1215
+ * have permission to write there" — which is the shape `writeHint` above was written to
1216
+ * replace, in the words of its own docstring: "Wrong advice is worse than none: it sends
1217
+ * someone to check `df` on a disk that is fine, and the thing that is actually wrong stays
1218
+ * unexamined." A full disk, a read-only volume and a path past the filesystem's length limit
1219
+ * all got advice about a path that exists and a permission that is not the problem, two lines
1220
+ * under a message where `describeFsError` had already named the cause exactly.
1221
+ *
1222
+ * No preamble, because nothing has been written yet — which is the only thing that differs
1223
+ * between the two, so the sentences themselves are shared rather than copied.
1224
+ */
1225
+ function createHint(cause) {
1226
+ return destinationAdvice(cause, 'choose another with --out', 'choose a shorter destination with --out');
1227
+ }
1228
+ /** The sentence an errno earns, with the two phrases that name where "somewhere else" is. */
1229
+ function destinationAdvice(cause, elsewhere, shorter) {
1208
1230
  const code = cause?.code;
1209
1231
  switch (code) {
1210
1232
  case 'ENOSPC':
1211
- return `${preamble}The destination is out of space; free some up or ${elsewhere}.`;
1233
+ return `The destination is out of space; free some up or ${elsewhere}.`;
1212
1234
  case 'EDQUOT':
1213
- return `${preamble}You are over your disk quota on this filesystem; ${elsewhere}.`;
1235
+ return `You are over your disk quota on this filesystem; ${elsewhere}.`;
1214
1236
  case 'EACCES':
1215
1237
  case 'EPERM':
1216
- return `${preamble}You do not have permission to write there; ${elsewhere}.`;
1238
+ return `You do not have permission to write there; ${elsewhere}.`;
1217
1239
  case 'EROFS':
1218
- return `${preamble}That filesystem is mounted read-only; ${elsewhere}.`;
1240
+ return `That filesystem is mounted read-only; ${elsewhere}.`;
1219
1241
  case 'EISDIR':
1220
- return `${preamble}A directory is sitting where that file belongs; remove or rename it, or ${elsewhere}.`;
1242
+ return `A directory is sitting where that file belongs; remove or rename it, or ${elsewhere}.`;
1221
1243
  case 'ENOENT':
1222
- return `${preamble}Part of that path no longer exists; make sure nothing is removing it while the conversion runs.`;
1244
+ return `Part of that path no longer exists; make sure nothing is removing it while the conversion runs.`;
1223
1245
  case 'ENAMETOOLONG':
1224
- return `${preamble}That path is longer than the filesystem allows; ${toStdout ? 'redirect it somewhere shorter' : 'choose a shorter destination with --out'}.`;
1246
+ return `That path is longer than the filesystem allows; ${shorter}.`;
1225
1247
  case 'EMFILE':
1226
1248
  case 'ENFILE':
1227
- return `${preamble}Too many files are open; a recording with many sampling rates opens one output file per rate, so --channels narrows it.`;
1249
+ return `Too many files are open; a recording with many sampling rates opens one output file per rate, so --channels narrows it.`;
1228
1250
  case 'EPIPE':
1229
- return `${preamble}Whatever was reading the output closed it before the conversion finished.`;
1251
+ return 'Whatever was reading the output closed it before the conversion finished.';
1230
1252
  default:
1231
- return `${preamble}Check the destination and run the conversion again.`;
1253
+ return 'Check the destination and run the conversion again.';
1232
1254
  }
1233
1255
  }
1234
1256
  /**