Skip to content

fix(langfuse): correct nil check variable typo in extractModelInput#785

Open
SKDG042 wants to merge 1 commit intocloudwego:mainfrom
SKDG042:fix/langfuse-nil-check-typo
Open

fix(langfuse): correct nil check variable typo in extractModelInput#785
SKDG042 wants to merge 1 commit intocloudwego:mainfrom
SKDG042:fix/langfuse-nil-check-typo

Conversation

@SKDG042
Copy link
Copy Markdown
Contributor

@SKDG042 SKDG042 commented Apr 17, 2026

What type of PR is this?

fix

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. User docs repo

(Optional) Translate the PR title into Chinese.

修正 extractModelInput 中 nil 检查的循环变量的使用错误,应当使用in而非ins

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:
In callbacks/langfuse/utils.go:38, the nil-check inside the for _, in := range ins loop was mistakenly comparing ins == nil (the slice itself) instead of in == nil (the current element). This makes the guard useless: when ins is nil, the loop body never executes; when ins is non-nil but contains nil elements, the guard always evaluates to false, and the subsequent in.Messages / in.Extra / in.Config accesses will panic on nil pointer dereference.

Before

for _, in := range ins {
    if ins == nil {   // bug: checks the slice, not the element
        continue
    }
    if len(in.Messages) > 0 { ... }  // panics if in is nil
}

After

  for _, in := range ins {
      if in == nil {    // correct: checks the current element
          continue
      }
      if len(in.Messages) > 0 { ... }
  }

zh(optional):
callbacks/langfuse/utils.go:38 中 for _, in := range ins 循环里的 nil 检查误将 in == nil(当前元素)写成了应该检查的 ins == nil(切片本身)。ins 为 nil 时循环根本不会进入;ins 非 nil 但含 nil 元素时,该判断恒为 false,后续 in.Messages 等访问会因空指针解引用 panic。

(Optional) Which issue(s) this PR fixes:

(optional) The PR that updates user documentation:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant