Skip to content

Commit 3a18dd1

Browse files
committed
refactor: Update StacError and StacErrorWidget for improved error handling
- Rename error parameter to errorDetails in StacErrorWidget for clarity. - Update documentation to reflect changes in error handling, including removal of stack trace display in the UI. - Ensure consistent usage of errorDetails across StacErrorWidget and related components.
1 parent 30daaa9 commit 3a18dd1

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

packages/stac/lib/src/framework/stac.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,18 @@ typedef LoadingWidgetBuilder = Widget Function(BuildContext context);
2222
/// Allows apps to provide a custom widget when parsing a Stac widget/action
2323
/// fails. The builder receives useful context like the widget/action type,
2424
/// original JSON and stack trace (when available).
25-
/// A simple error widget builder: provide a context and structured details.
25+
///
26+
/// Example:
27+
/// ```dart
28+
/// Stac.initialize(
29+
/// errorWidgetBuilder: (context, errorDetails) {
30+
/// return Text('Error in ${errorDetails.type}: ${errorDetails.error}');
31+
/// },
32+
/// );
33+
/// ```
2634
typedef StacErrorWidgetBuilder = Widget Function(
2735
BuildContext context,
28-
StacError details,
36+
StacError errorDetails,
2937
);
3038

3139
class Stac extends StatelessWidget {

packages/stac/lib/src/framework/stac_error.dart

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import 'package:flutter/material.dart';
2424
///
2525
/// // Using with error widget builder
2626
/// Stac.initialize(
27-
/// errorWidgetBuilder: (context, details) {
28-
/// return Text('Error in ${details.type}: ${details.error}');
27+
/// errorWidgetBuilder: (context, errorDetails) {
28+
/// return Text('Error in ${errorDetails.type}: ${errorDetails.error}');
2929
/// },
3030
/// );
3131
/// ```
@@ -96,31 +96,33 @@ class StacError {
9696
/// A widget that displays detailed error information when Stac fails to parse JSON.
9797
///
9898
/// Shown when parsing fails, providing developers with context about what went wrong,
99-
/// including the error type, message, JSON payload, and stack trace when available.
99+
/// including the error type, message, and JSON payload when available.
100100
///
101101
/// Features:
102-
/// - Expandable error details with JSON and stack trace
103-
/// - Context-aware troubleshooting tips
102+
/// - Expandable error details with JSON payload
103+
/// - Context-aware troubleshooting tips based on error type
104104
/// - Copy-friendly selectable text for debugging
105105
///
106+
/// Note: Stack traces are logged to the console but not displayed in the UI.
107+
/// Use a custom [StacErrorWidgetBuilder] if you need to display stack traces.
108+
///
106109
/// Example:
107110
/// ```dart
108111
/// StacErrorWidget(
109112
/// error: StacError(
110113
/// type: 'container',
111114
/// error: FormatException('Invalid value'),
112115
/// json: {'type': 'container', 'padding': 'invalid'},
113-
/// stackTrace: StackTrace.current,
114116
/// ),
115117
/// )
116118
/// ```
117119
class StacErrorWidget extends StatefulWidget {
118120
const StacErrorWidget({
119121
super.key,
120-
required this.error,
122+
required this.errorDetails,
121123
});
122124

123-
final StacError error;
125+
final StacError errorDetails;
124126

125127
@override
126128
State<StacErrorWidget> createState() => _StacErrorWidgetState();
@@ -195,8 +197,8 @@ class _StacErrorWidgetState extends State<StacErrorWidget> {
195197
const SizedBox(height: 8),
196198

197199
// Type information (always visible, null-safe)
198-
if (widget.error.type != null) ...[
199-
_buildInfoRow('Type', widget.error.type!),
200+
if (widget.errorDetails.type != null) ...[
201+
_buildInfoRow('Type', widget.errorDetails.type!),
200202
const SizedBox(height: 4),
201203
],
202204

@@ -215,7 +217,7 @@ class _StacErrorWidgetState extends State<StacErrorWidget> {
215217
const SizedBox(width: 8),
216218
Expanded(
217219
child: Text(
218-
widget.error.error.toString(),
220+
widget.errorDetails.error.toString(),
219221
style: const TextStyle(
220222
color: _errorRed,
221223
fontSize: 13,
@@ -233,12 +235,12 @@ class _StacErrorWidgetState extends State<StacErrorWidget> {
233235
const SizedBox(height: 8),
234236

235237
// JSON data
236-
if (widget.error.json != null) ...[
238+
if (widget.errorDetails.json != null) ...[
237239
_buildExpandableSection(
238240
title: 'JSON Data',
239241
section: _ExpandableSection.json,
240242
child: _buildCodeBlock(
241-
_formatJson(widget.error.json!),
243+
_formatJson(widget.errorDetails.json!),
242244
),
243245
),
244246
const SizedBox(height: 8),
@@ -398,8 +400,9 @@ class _StacErrorWidgetState extends State<StacErrorWidget> {
398400
}
399401

400402
String _getTroubleshootingTips() {
401-
final errorStr = widget.error.error.toString().toLowerCase();
402-
final errorType = widget.error.error.runtimeType.toString().toLowerCase();
403+
final errorStr = widget.errorDetails.error.toString().toLowerCase();
404+
final errorType =
405+
widget.errorDetails.error.runtimeType.toString().toLowerCase();
403406

404407
// Check for unregistered widget/action types
405408
if (errorStr.contains('type') && errorStr.contains('not found')) {

packages/stac/lib/src/framework/stac_service.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,6 @@ class StacService {
489489
return _errorWidgetBuilder!(context, error);
490490
}
491491

492-
return StacErrorWidget(error: error);
492+
return StacErrorWidget(errorDetails: error);
493493
}
494494
}

0 commit comments

Comments
 (0)