Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ output/
*.dylib
*.db
*.bin
openlist

# Test binary, built with `go test -c`
*.test
Expand Down
102 changes: 102 additions & 0 deletions ENHANCED_LOGGING_EXAMPLE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Enhanced Logging Example

## What Changed

The logging for the `complete()` polling has been enhanced to always show the full API response details, even when errors occur.

## Before Enhancement

When the API returned an error, only the error message was logged:

```log
WARN[2025-12-28 17:31:18] [123open] File: sharedassets5.assets.resS - Complete poll #1: API error: 文件正在校验中,请间隔1秒后再试
WARN[2025-12-28 17:31:19] [123open] File: sharedassets5.assets.resS - Complete poll #2: API error: 文件上传失败
```

**Problem**: We couldn't see the actual error Code that the API returned. The Code value was lost in the error conversion.

## After Enhancement

Now, the full API response is logged even when there's an error:

```log
WARN[2025-12-28 17:31:18] [123open] File: sharedassets5.assets.resS - Complete poll #1: Code=10001, Message=文件正在校验中,请间隔1秒后再试, Completed=false, FileID=0 (API Error: 文件正在校验中,请间隔1秒后再试)
WARN[2025-12-28 17:31:19] [123open] File: sharedassets5.assets.resS - Complete poll #2: Code=20103, Message=文件上传失败, Completed=false, FileID=0 (API Error: 文件上传失败)
```

**Benefit**: Now we can see:
- The actual error **Code** (e.g., 10001, 20103)
- The error **Message** (Chinese text)
- The **Completed** status (false)
- The **FileID** value (0)
- The original error for context

## Why This Matters

The error codes are undocumented or poorly documented in the 123open API. By capturing the actual Code values, we can:

1. **Identify patterns**: Does error code 20103 always mean "upload failed"?
2. **Distinguish error types**: Is code 10001 a "processing" state vs 20103 a "failure" state?
3. **Debug edge cases**: What other error codes exist that we haven't seen?
4. **Implement proper handling**: Once we know the codes, we can handle them specifically

## Implementation Details

### Code Changes

1. **In `drivers/123_open/upload.go` - `complete()` function**:
- Changed from `return nil, err` to `return &resp, err` on error
- This ensures the response struct is returned even when there's an error
- The response struct contains the parsed API response with Code, Message, etc.

2. **In `drivers/123_open/driver.go` - `Put()` method**:
- Updated the error logging to access `uploadCompleteResp` fields directly
- Added Code, Message, Completed, and FileID to the warning log
- Kept the error message at the end for context

### Why This Works

The `Request()` function in `util.go` already parses the response into the struct before returning an error. Our change ensures that parsed response is not discarded when an error occurs, allowing the caller to log all the details.

## Expected Diagnostic Value

With this enhanced logging, when users encounter the timeout issue, we'll see exactly what the 123open API is returning:

### Scenario 1: Processing Delay
```log
Poll #1: Code=0, Message=文件正在校验中, Completed=false, FileID=0
Poll #2: Code=0, Message=文件正在校验中, Completed=false, FileID=0
...
Poll #10: Code=0, Message=, Completed=true, FileID=123456
```
**Diagnosis**: Server just needs more time, increase polling duration.

### Scenario 2: Validation Failure
```log
Poll #1: Code=0, Message=文件正在校验中, Completed=false, FileID=0
Poll #2: Code=20103, Message=文件上传失败, Completed=false, FileID=0
Poll #3-60: Code=20103, Message=文件上传失败, Completed=false, FileID=0
```
**Diagnosis**: Upload validation failed (possibly MD5 mismatch), need to investigate data integrity.

### Scenario 3: Unknown Error Code
```log
Poll #1-60: Code=99999, Message=未知错误, Completed=false, FileID=0
```
**Diagnosis**: Undocumented error code, need to contact 123open support or find workaround.

## Testing

To verify the enhancement works correctly:

1. Build the project: `go build -tags jsoniter -o openlist .`
2. Run OpenList with INFO or DEBUG logging enabled
3. Attempt to copy a file from Baidu to 123open
4. Check the logs for the enhanced complete() polling output
5. Verify all fields are present in both success and error cases

## Related Documentation

- Technical analysis: See `ANALYSIS_123OPEN_TIMEOUT.md` section on "Hypothesis 3: Server-Side Processing Delay"
- Debug guide: See `DEBUG_GUIDE.md` section on "Scenario 2: Unknown Error Code"
- Testing: See `TESTING_SCENARIOS.md` for systematic test cases
4 changes: 3 additions & 1 deletion PR_SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Three files modified to add detailed logging:

#### `drivers/123_open/driver.go`
- Upload lifecycle tracking (start, MD5 computation, creation, upload, polling)
- **Most critical**: Every `complete()` poll attempt logs full API response
- **Most critical**: Every `complete()` poll attempt logs full API response including Code, Message, Completed, and FileID - even when API returns errors
- Timing metrics for each phase
- Success/failure status with context

Expand Down Expand Up @@ -82,6 +82,8 @@ The key to solving this issue is in the `complete()` API response logs:
[123open] File: <filename> - Complete poll #N: Code=<code>, Message=<msg>, Completed=<bool>, FileID=<id>
```

**Enhancement**: The logging now captures the full API response even when errors occur. This means we'll see the actual error Code (e.g., 20103) alongside the error Message, Completed status, and FileID value, providing complete diagnostic information for every poll attempt.

This will reveal:
- ✅ What error codes the 123open API actually returns (including the mysterious error code 20103 mentioned in comments)
- ✅ What error messages are provided (if any)
Expand Down
7 changes: 5 additions & 2 deletions drivers/123_open/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,12 @@ func (d *Open123) Put(ctx context.Context, dstDir model.Obj, file model.FileStre
for i := range 60 {
uploadCompleteResp, err := d.complete(createResp.Data.PreuploadID)

// 详细记录每次轮询的结果
// 详细记录每次轮询的结果 - 始终记录完整的响应信息
if err != nil {
log.Warnf("[123open] File: %s - Complete poll #%d: API error: %v", fileName, i+1, err)
// API返回了错误,但我们仍然记录响应中的所有可用信息
log.Warnf("[123open] File: %s - Complete poll #%d: Code=%d, Message=%s, Completed=%v, FileID=%d (API Error: %v)",
fileName, i+1, uploadCompleteResp.Code, uploadCompleteResp.Message,
uploadCompleteResp.Data.Completed, uploadCompleteResp.Data.FileID, err)
} else {
log.Infof("[123open] File: %s - Complete poll #%d: Code=%d, Message=%s, Completed=%v, FileID=%d",
fileName, i+1, uploadCompleteResp.Code, uploadCompleteResp.Message,
Expand Down
3 changes: 2 additions & 1 deletion drivers/123_open/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,9 @@ func (d *Open123) complete(preuploadID string) (*UploadCompleteResp, error) {
"preuploadID": preuploadID,
})
}, &resp)
// 返回响应体即使有错误,以便调用者可以记录详细信息
if err != nil {
return nil, err
return &resp, err
}
return &resp, nil
}
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,6 @@ github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7Fsg
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/halalcloud/golang-sdk-lite v0.0.0-20251006164234-3c629727c499 h1:4ovnBdiGDFi8putQGxhipuuhXItAgh4/YnzufPYkZkQ=
github.com/halalcloud/golang-sdk-lite v0.0.0-20251006164234-3c629727c499/go.mod h1:8x1h4rm3s8xMcTyJrq848sQ6BJnKzl57mDY4CNshdPM=
github.com/halalcloud/golang-sdk-lite v0.0.0-20251105081800-78cbb6786c38 h1:lsK2GVgI2Ox0NkRpQnN09GBOH7jtsjFK5tcIgxXlLr0=
github.com/halalcloud/golang-sdk-lite v0.0.0-20251105081800-78cbb6786c38/go.mod h1:8x1h4rm3s8xMcTyJrq848sQ6BJnKzl57mDY4CNshdPM=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand Down