mirror of
https://github.com/foss42/apidash.git
synced 2025-12-01 02:07:00 +08:00
Replace print with debugPrint and improve logging
Replaced print statements with debugPrint in tests for better Flutter logging practices. In js_runtime_notifier.dart, replaced print statements with structured logging via terminalStateProvider, providing more consistent and contextual log handling. Minor code style improvements were also made.
This commit is contained in:
@@ -50,7 +50,9 @@ class APIDashRequestDescription {
|
|||||||
if (bodyJSON != null) {
|
if (bodyJSON != null) {
|
||||||
getTyp(input, [i = 0]) {
|
getTyp(input, [i = 0]) {
|
||||||
String indent = "\t";
|
String indent = "\t";
|
||||||
for (int j = 0; j < i; j++) indent += "\t";
|
for (int j = 0; j < i; j++) {
|
||||||
|
indent += "\t";
|
||||||
|
}
|
||||||
if (input.runtimeType.toString().toLowerCase().contains('map')) {
|
if (input.runtimeType.toString().toLowerCase().contains('map')) {
|
||||||
String typd = '{';
|
String typd = '{';
|
||||||
for (final z in input.keys) {
|
for (final z in input.keys) {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// ignore_for_file: avoid_print
|
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:apidash_core/apidash_core.dart';
|
import 'package:apidash_core/apidash_core.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
@@ -307,8 +306,16 @@ class JsRuntimeNotifier extends StateNotifier<JsRuntimeState> {
|
|||||||
updateEnv?.call(originalEnvironmentModel, newValues);
|
updateEnv?.call(originalEnvironmentModel, newValues);
|
||||||
} else {
|
} else {
|
||||||
if (scriptResult.updatedEnvironment.isNotEmpty) {
|
if (scriptResult.updatedEnvironment.isNotEmpty) {
|
||||||
print(
|
final term = ref.read(terminalStateProvider.notifier);
|
||||||
'Warning: Pre-request script updated environment variables, but no active environment was selected to save them to.');
|
final msg =
|
||||||
|
'Pre-request script updated environment variables, but no active environment was selected to save them to.';
|
||||||
|
state = state.copyWith(lastError: msg);
|
||||||
|
term.logJs(
|
||||||
|
level: 'warn',
|
||||||
|
args: [msg],
|
||||||
|
context: 'preRequest',
|
||||||
|
contextRequestId: requestModel.id,
|
||||||
|
);
|
||||||
return requestModel;
|
return requestModel;
|
||||||
}
|
}
|
||||||
return newRequestModel;
|
return newRequestModel;
|
||||||
@@ -359,8 +366,16 @@ class JsRuntimeNotifier extends StateNotifier<JsRuntimeState> {
|
|||||||
updateEnv?.call(originalEnvironmentModel, newValues);
|
updateEnv?.call(originalEnvironmentModel, newValues);
|
||||||
} else {
|
} else {
|
||||||
if (scriptResult.updatedEnvironment.isNotEmpty) {
|
if (scriptResult.updatedEnvironment.isNotEmpty) {
|
||||||
print(
|
final term = ref.read(terminalStateProvider.notifier);
|
||||||
'Warning: Post-response script updated environment variables, but no active environment was selected to save them to.');
|
final msg =
|
||||||
|
'Post-response script updated environment variables, but no active environment was selected to save them to.';
|
||||||
|
state = state.copyWith(lastError: msg);
|
||||||
|
term.logJs(
|
||||||
|
level: 'warn',
|
||||||
|
args: [msg],
|
||||||
|
context: 'postResponse',
|
||||||
|
contextRequestId: requestModel.id,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return requestModel;
|
return requestModel;
|
||||||
}
|
}
|
||||||
@@ -375,8 +390,8 @@ class JsRuntimeNotifier extends StateNotifier<JsRuntimeState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _handleConsole(String level, dynamic args) {
|
void _handleConsole(String level, dynamic args) {
|
||||||
|
final term = ref.read(terminalStateProvider.notifier);
|
||||||
try {
|
try {
|
||||||
final term = ref.read(terminalStateProvider.notifier);
|
|
||||||
List<String> argList = const <String>[];
|
List<String> argList = const <String>[];
|
||||||
if (args is List) {
|
if (args is List) {
|
||||||
argList = args.map((e) => e.toString()).toList();
|
argList = args.map((e) => e.toString()).toList();
|
||||||
@@ -398,13 +413,16 @@ class JsRuntimeNotifier extends StateNotifier<JsRuntimeState> {
|
|||||||
term.logJs(
|
term.logJs(
|
||||||
level: level, args: argList, contextRequestId: _currentRequestId);
|
level: level, args: argList, contextRequestId: _currentRequestId);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('[JS ${level.toUpperCase()} HANDLER ERROR]: $args, Error: $e');
|
term.logSystem(
|
||||||
|
category: 'provider',
|
||||||
|
message:
|
||||||
|
'[JS ${level.toUpperCase()} HANDLER ERROR]: $args, Error: $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleFatal(dynamic args) {
|
void _handleFatal(dynamic args) {
|
||||||
|
final term = ref.read(terminalStateProvider.notifier);
|
||||||
try {
|
try {
|
||||||
final term = ref.read(terminalStateProvider.notifier);
|
|
||||||
if (args is Map<String, dynamic>) {
|
if (args is Map<String, dynamic>) {
|
||||||
final message = args['message']?.toString() ?? 'Unknown fatal error';
|
final message = args['message']?.toString() ?? 'Unknown fatal error';
|
||||||
final error = args['error']?.toString();
|
final error = args['error']?.toString();
|
||||||
@@ -424,7 +442,9 @@ class JsRuntimeNotifier extends StateNotifier<JsRuntimeState> {
|
|||||||
contextRequestId: _currentRequestId);
|
contextRequestId: _currentRequestId);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('[JS FATAL ERROR decoding error]: $args, Error: $e');
|
term.logSystem(
|
||||||
|
category: 'provider',
|
||||||
|
message: '[JS FATAL ERROR decoding error]: $args, Error: $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -746,9 +746,10 @@ void main() {
|
|||||||
|
|
||||||
// First verify we can find String popup menus
|
// First verify we can find String popup menus
|
||||||
final stringPopupMenus = find.byType(ADPopupMenu<String>);
|
final stringPopupMenus = find.byType(ADPopupMenu<String>);
|
||||||
print('Found ${stringPopupMenus.evaluate().length} String popup menus');
|
debugPrint(
|
||||||
|
'Found ${stringPopupMenus.evaluate().length} String popup menus');
|
||||||
|
|
||||||
if (stringPopupMenus.evaluate().length > 0) {
|
if (stringPopupMenus.evaluate().isNotEmpty) {
|
||||||
// Find the code challenge method dropdown
|
// Find the code challenge method dropdown
|
||||||
final codeChallengeDropdown = stringPopupMenus.first;
|
final codeChallengeDropdown = stringPopupMenus.first;
|
||||||
await tester.tap(codeChallengeDropdown);
|
await tester.tap(codeChallengeDropdown);
|
||||||
@@ -756,7 +757,7 @@ void main() {
|
|||||||
|
|
||||||
// Try to find and tap plaintext option
|
// Try to find and tap plaintext option
|
||||||
final plaintextOption = find.text('Plaintext');
|
final plaintextOption = find.text('Plaintext');
|
||||||
if (plaintextOption.evaluate().length > 0) {
|
if (plaintextOption.evaluate().isNotEmpty) {
|
||||||
await tester.tap(plaintextOption.first);
|
await tester.tap(plaintextOption.first);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
@@ -852,19 +853,19 @@ void main() {
|
|||||||
|
|
||||||
// Debug: Print all text widgets to see what's available
|
// Debug: Print all text widgets to see what's available
|
||||||
final allText = find.byType(Text);
|
final allText = find.byType(Text);
|
||||||
print('Found ${allText.evaluate().length} Text widgets');
|
debugPrint('Found ${allText.evaluate().length} Text widgets');
|
||||||
|
|
||||||
// Try to find any button-like widget
|
// Try to find any button-like widget
|
||||||
final allButtons = find.byType(ADTextButton);
|
final allButtons = find.byType(ADTextButton);
|
||||||
print('Found ${allButtons.evaluate().length} ADTextButton widgets');
|
debugPrint('Found ${allButtons.evaluate().length} ADTextButton widgets');
|
||||||
|
|
||||||
// Look for the specific text content
|
// Look for the specific text content
|
||||||
final clearText = find.text('Clear OAuth2 Session');
|
final clearText = find.text('Clear OAuth2 Session');
|
||||||
print(
|
debugPrint(
|
||||||
'Found ${clearText.evaluate().length} widgets with Clear OAuth2 Session text');
|
'Found ${clearText.evaluate().length} widgets with Clear OAuth2 Session text');
|
||||||
|
|
||||||
// If we can find the clear button text, tap it
|
// If we can find the clear button text, tap it
|
||||||
if (clearText.evaluate().length > 0) {
|
if (clearText.evaluate().isNotEmpty) {
|
||||||
await tester.tap(clearText.first);
|
await tester.tap(clearText.first);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
}
|
}
|
||||||
@@ -1296,10 +1297,10 @@ void main() {
|
|||||||
|
|
||||||
// Debug: Look for all buttons and text widgets
|
// Debug: Look for all buttons and text widgets
|
||||||
final allButtons = find.byType(ADTextButton);
|
final allButtons = find.byType(ADTextButton);
|
||||||
print('Found ${allButtons.evaluate().length} ADTextButton widgets');
|
debugPrint('Found ${allButtons.evaluate().length} ADTextButton widgets');
|
||||||
|
|
||||||
final allText = find.byType(Text);
|
final allText = find.byType(Text);
|
||||||
print('Found ${allText.evaluate().length} Text widgets');
|
debugPrint('Found ${allText.evaluate().length} Text widgets');
|
||||||
|
|
||||||
// Try finding the button widget itself
|
// Try finding the button widget itself
|
||||||
if (allButtons.evaluate().isNotEmpty) {
|
if (allButtons.evaluate().isNotEmpty) {
|
||||||
|
|||||||
Reference in New Issue
Block a user