How to use the @parcel/diagnostic.errorToDiagnostic function in @parcel/diagnostic

To help you get started, we’ve selected a few @parcel/diagnostic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github parcel-bundler / parcel / packages / core / core / src / ReporterRunner.js View on Github external
async report(event: ReporterEvent) {
    let reporters = await this.config.getReporters();

    for (let reporter of reporters) {
      try {
        await reporter.plugin.report({
          event,
          options: this.pluginOptions,
          logger: new PluginLogger({origin: reporter.name}),
        });
      } catch (e) {
        throw new ThrowableDiagnostic({
          diagnostic: errorToDiagnostic(e, reporter.name),
        });
      }
    }
  }
}
github parcel-bundler / parcel / packages / core / core / src / BundlerRunner.js View on Github external
throw new Error(
              `Destination name ${name} extension does not match bundle type "${bundle.type}"`,
            );
          }

          let target = nullthrows(internalBundle.target);
          internalBundle.filePath = path.join(
            target.distDir,
            normalizeSeparators(name),
          );
          internalBundle.name = name;
          return;
        }
      } catch (e) {
        throw new ThrowableDiagnostic({
          diagnostic: errorToDiagnostic(e, namer.name),
        });
      }
    }

    throw new Error('Unable to name bundle');
  }
}
github parcel-bundler / parcel / packages / core / core / src / ResolverRunner.js View on Github external
if (result && result.isExcluded) {
          return null;
        }

        if (result && result.filePath) {
          return {
            filePath: result.filePath,
            sideEffects: result.sideEffects,
            code: result.code,
            env: dependency.env,
            pipeline: pipeline ?? dependency.pipeline
          };
        }
      } catch (e) {
        throw new ThrowableDiagnostic({
          diagnostic: errorToDiagnostic(e, resolver.name)
        });
      }
    }

    if (dep.isOptional) {
      return null;
    }

    let dir = dependency.sourcePath
      ? path.dirname(dependency.sourcePath)
      : '';

    let err: any = await this.getThrowableDiagnostic(
      dependency,
      `Cannot find module '${dependency.moduleSpecifier}' from '${dir}'`
    );
github parcel-bundler / parcel / packages / core / core / src / PackagerRunner.js View on Github external
bundle,
    });

    let optimized = {contents, map};
    for (let optimizer of optimizers) {
      try {
        optimized = await optimizer.plugin.optimize({
          bundle,
          contents: optimized.contents,
          map: optimized.map,
          options: this.pluginOptions,
          logger: new PluginLogger({origin: optimizer.name}),
        });
      } catch (e) {
        throw new ThrowableDiagnostic({
          diagnostic: errorToDiagnostic(e, optimizer.name),
        });
      }
    }

    return optimized;
  }
github parcel-bundler / parcel / packages / core / core / src / Transformation.js View on Github external
try {
          let transformerResults = await runTransformer(
            pipeline,
            asset,
            transformer.plugin,
            transformer.name,
            transformer.config,
          );

          for (let result of transformerResults) {
            resultingAssets.push(asset.createChildAsset(result));
          }
        } catch (e) {
          throw new ThrowableDiagnostic({
            diagnostic: errorToDiagnostic(e, transformer.name),
          });
        }
      }
      inputAssets = resultingAssets;
    }

    finalAssets = finalAssets.concat(resultingAssets);

    return Promise.all(
      finalAssets.map(asset =>
        finalize(nullthrows(asset), nullthrows(pipeline.generate)),
      ),
    );
  }
github parcel-bundler / parcel / packages / core / logger / src / Logger.js View on Github external
function messagesToDiagnostic(
  messages: Array,
): Diagnostic | Array {
  if (messages.length === 1 && messages[0] instanceof Error) {
    let error: Error = messages[0];
    let diagnostic = errorToDiagnostic(error);

    if (Array.isArray(diagnostic)) {
      return diagnostic.map(d => {
        return {
          ...d,
          skipFormatting: true,
        };
      });
    } else {
      return {
        ...diagnostic,
        skipFormatting: true,
      };
    }
  } else {
    return {
github parcel-bundler / parcel / packages / core / core / src / Validation.js View on Github external
if (validatorResult) {
          let {warnings, errors} = validatorResult;

          if (errors.length > 0) {
            throw new ThrowableDiagnostic({
              diagnostic: errors,
            });
          }

          if (warnings.length > 0) {
            logger.warn(warnings);
          }
        }
      } catch (e) {
        throw new ThrowableDiagnostic({
          diagnostic: errorToDiagnostic(e, validator.name),
        });
      }
    }
  }

@parcel/diagnostic

MIT
Latest version published 2 months ago

Package Health Score

89 / 100
Full package analysis

Similar packages