import sys filepath = r'C:\Users\jsmbz\Documents\flutter-app-02\lib\features\devices\data\repositories\generate_path_repository_Impl.dart' with open(filepath, 'r', encoding='utf-8') as f: content = f.read() old = ''' if (response.statusCode != 200) { throw Exception('创建设备任务失败: HTTP ${response.statusCode}'); } } catch (e) { print('❌ [创建设备任务] 错误: $e'); throw Exception('创建设备任务失败: $e'); }''' new = ''' if (response.statusCode != 200) { throw Exception('创建设备任务失败: HTTP ${response.statusCode}'); } // 解析响应,提取 taskId final data = jsonDecode(response.body) as Map; if (data['code'] == 200) { final taskData = data['data']; if (taskData is int) { print('✅ [创建设备任务] 任务ID: $taskData'); return taskData; } else if (taskData is Map) { final taskId = taskData['id'] ?? taskData['taskId']; if (taskId is int) { print('✅ [创建设备任务] 任务ID: $taskId'); return taskId; } } throw Exception('创建设备任务成功但无法解析taskId: ${response.body}'); } else { throw Exception('创建设备任务失败: ${data['msg'] ?? response.body}'); } } catch (e) { print('❌ [创建设备任务] 错误: $e'); throw Exception('创建设备任务失败: $e'); }''' if old in content: content = content.replace(old, new) with open(filepath, 'w', encoding='utf-8') as f: f.write(content) print('SUCCESS') else: print('NOT FOUND') # Debug: find the line for i, line in enumerate(content.split('\n'), 1): if '创建设备任务失败: HTTP' in line: print(f'Line {i}: {repr(line)}')