Skip to content

Conversation

@NullSnow
Copy link

  • 在 CreateTranscriptionsReq 类中的 of(File file) 方法中增加了设置文件名的逻辑
  • 解决TranscriptionService中获取文件名为空,导致的接口返回 {"detail":{"logid":"xxxx"},"code":4000,"msg":"The parameter file is invalid. It should follow the format: file. Please review your input."}

- 在 CreateTranscriptionsReq 类中的 of(File file) 方法中增加了设置文件名的逻辑
- 解决TranscriptionService中获取文件名为空,导致的接口返回 {"detail":{"logid":"2025082610304671C0F5314D04A5EED067"},"code":4000,"msg":"The parameter file is invalid. It should follow the format: file. Please review your input."}
@CLAassistant
Copy link

CLAassistant commented Aug 26, 2025

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link

coderabbitai bot commented Aug 26, 2025

Walkthrough

Populates fileName in CreateTranscriptionsReq.of(File) by setting it from file.getName() alongside the existing file assignment. No public API signatures changed.

Changes

Cohort / File(s) Summary of Changes
Audio transcription request builder
api/src/main/java/com/coze/openapi/client/audio/transcriptions/CreateTranscriptionsReq.java
In of(File), builder now sets fileName using file.getName() in addition to setting file.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nibble code like clover leaves so green,
A filename sprouted where none had been.
Hop, set, done—no methods rearranged,
Just tidy fields now neatly named.
Thump-thump! My paws approve this scene.

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
api/src/main/java/com/coze/openapi/client/audio/transcriptions/CreateTranscriptionsReq.java (1)

39-41: Populate fileName in of(String filePath) for consistency

Callers of CreateTranscriptionsReq.of(String) currently omit fileName, which can trigger server-side validation failures. There’s one usage in the example code—no other production call sites or builder chains (setting only filePath) were found—so deriving fileName is safe and prevents future issues.

Call site to update:

  • example/src/main/java/example/audio/transcriptions/CreateTranscriptionExample.java:21

Suggested implementation:

public static CreateTranscriptionsReq of(String filePath) {
  if (filePath == null || filePath.isEmpty()) {
    throw new IllegalArgumentException("filePath must not be null/empty");
  }
  String name = java.nio.file.Paths.get(filePath).getFileName().toString();
  return CreateTranscriptionsReq.builder()
      .filePath(filePath)
      .fileName(name)
      .build();
}
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ffd3528 and a4ff682.

📒 Files selected for processing (1)
  • api/src/main/java/com/coze/openapi/client/audio/transcriptions/CreateTranscriptionsReq.java (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: test (Java 17 on Windows)
  • GitHub Check: test (Java 11 on Windows)
🔇 Additional comments (1)
api/src/main/java/com/coze/openapi/client/audio/transcriptions/CreateTranscriptionsReq.java (1)

35-37: Good fix: setting fileName from File resolves the API's “invalid file” error.

Populating fileName via file.getName() in of(File) directly addresses the server-side validation issue without changing public APIs. Looks correct and low-risk.

Comment on lines 35 to 37
public static CreateTranscriptionsReq of(File file) {
return CreateTranscriptionsReq.builder().file(file).build();
return CreateTranscriptionsReq.builder().file(file).fileName(file.getName()).build();
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add null-check and guard against empty getName() to avoid NPE/invalid names

If file is null, this method throws NPE. Also, File#getName() can be empty for edge cases (e.g., platform root paths). Add validation and a fallback.

Apply this diff within this method:

   public static CreateTranscriptionsReq of(File file) {
-    return CreateTranscriptionsReq.builder().file(file).fileName(file.getName()).build();
+    if (file == null) {
+      throw new IllegalArgumentException("file must not be null");
+    }
+    String name = file.getName();
+    if (name == null || name.isEmpty()) {
+      // Fallback for unconventional paths (e.g., root). Use path as a last resort.
+      name = file.getPath();
+    }
+    return CreateTranscriptionsReq.builder()
+        .file(file)
+        .fileName(name)
+        .build();
   }

Optional: annotate the parameter with Lombok @NonNull to enforce checks at compile-time as well.

🤖 Prompt for AI Agents
In
api/src/main/java/com/coze/openapi/client/audio/transcriptions/CreateTranscriptionsReq.java
around lines 35-37, the factory method blindly uses file and file.getName(),
which can cause NPE if file is null and can yield an empty filename for edge
cases; add a null-check that throws a clear IllegalArgumentException (or return
an Optional/handle per project convention) when file is null, compute name =
file.getName(); if name is null or empty use a sensible fallback like "unknown"
or derive from file.getPath(), then build with that name; optionally annotate
the parameter with Lombok @NonNull to enforce compile-time checks.

@NullSnow NullSnow changed the title fix(api-client): 修复文件名为空导致的异常 fix: 修复文件名为空导致的异常 Aug 26, 2025
@NullSnow NullSnow closed this Aug 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants