CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-angular-devkit--build-ng-packagr

Angular Build Architect builder for ng-packagr library packaging (deprecated)

89

1.00x
Overview
Eval results
Files

task.mdevals/scenario-9/

Builder Error Handler

Build a custom Angular Architect builder that demonstrates proper error handling patterns when integrating external tools. The builder should wrap a command-line tool execution and handle various error scenarios gracefully.

Requirements

Implement a builder that executes a hypothetical package bundler and handles errors according to Angular Architect conventions:

  1. Return Format: The builder must return results in the standard format with a success boolean field and optional error message field
  2. Non-throwing Error Handling: Errors should be caught and returned as failed build results rather than thrown exceptions
  3. Missing Dependency Detection: Check if the required external package is installed and provide actionable error messages if missing
  4. Error Type Handling: Properly handle different error types (missing modules, runtime errors, etc.)
  5. Graceful Degradation: The builder should never crash - all errors should be caught and reported appropriately

Builder Configuration

The builder should accept these options:

interface BundlerOptions {
  configFile: string;    // Path to bundler config
  outputPath?: string;   // Optional output directory
}

Error Scenarios to Handle

  1. Missing Package: The external bundler package (my-bundler) is not installed
  2. Invalid Configuration: The config file doesn't exist or is malformed
  3. Build Failures: The bundler process fails during execution
  4. Unexpected Errors: Any other runtime errors

Expected Behavior

  • When the bundler package is missing, return a clear message guiding the user to install it
  • When configuration is invalid, explain what's wrong
  • When the build fails, include the underlying error message
  • Always return { success: false, error: "..." } for failures, never throw

Test Cases

  • It returns success false when the bundler package is not installed @test
  • It returns success false with error message when config file is missing @test
  • It returns success true when build completes successfully @test
  • It catches and reports runtime errors without throwing @test

Implementation

@generates

API

import { BuilderContext, BuilderOutput } from '@angular-devkit/architect';
import { Observable } from 'rxjs';

export interface BundlerOptions {
  configFile: string;
  outputPath?: string;
}

export function executeBundlerBuilder(
  options: BundlerOptions,
  context: BuilderContext
): Observable<BuilderOutput>;

Dependencies { .dependencies }

@angular-devkit/architect { .dependency }

Provides the Angular Architect builder infrastructure including BuilderContext and BuilderOutput types.

rxjs { .dependency }

Provides Observable support for reactive build process management.

Install with Tessl CLI

npx tessl i tessl/npm-angular-devkit--build-ng-packagr

tile.json