Skip to content

feat: replace print(e)/print(stack) with logging package in generated error handler #150

@Barba2k2

Description

@Barba2k2

Problem

The generated vaden_application.dart uses raw print(e) and print(stack) in the global exception handler:

// vaden_application.dart (auto-generated)
} catch (e, stack) {
  print(e);
  print(stack);
  return _handleException(e);
}

This produces noisy, unformatted stack traces for every caught exception — including expected ones like auth failures (400/401). In production, this clutters logs and makes it hard to distinguish real errors from normal flow.

Proposed Solution

Use the official logging package (by dart.dev) instead of print():

import 'package:logging/logging.dart';

final _logger = Logger('VadenApp');

// ...
} catch (e, stack) {
  _logger.severe('Unhandled exception', e, stack);
  return _handleException(e);
}

Benefits

  • Structured output — timestamps, log levels, and source names
  • Filterable — users can set log levels to suppress noise
  • Consistent — aligns with Dart ecosystem standard (logging has 5M+ downloads)
  • Configurable — apps can attach their own log handlers (file, remote, formatted console)

Alternative

At minimum, skip printing stack traces for exceptions handled by @ControllerAdvice (e.g., ResponseException, DioException), since those are expected application errors, not crashes.

Environment

  • Vaden: 1.0.2
  • Dart SDK: 3.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions