andygrunwald / go-jira

Go client library for Atlassian Jira
https://pkg.go.dev/github.com/andygrunwald/go-jira?tab=doc
MIT License
1.47k stars 469 forks source link

Error while creating jira story #376

Open sonalp123 opened 3 years ago

sonalp123 commented 3 years ago

2021/05/11 16:41:09 ERROR: request failed. Please analyze the request body for more details. Status code: 400

panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x1271f8d]

goroutine 1 [running]: main.main() /Users/Documents/jiratrial.go:44 +0x3ad exit status 2

package main

import (
    "fmt"
    jira "github.com/andygrunwald/go-jira"
    "log"
)

func main() {
    base := "https://jira.com"
    tp := jira.BasicAuthTransport{
        Username: "<username>",
        Password: "<password>",
    }

    jiraClient, err := jira.NewClient(tp.Client(), base)
    if err != nil {
        log.Println(err)
    }

    i := jira.Issue{
        Fields: &jira.IssueFields{
            Assignee: &jira.User{
                AccountID: "<username>",
            },
            Reporter: &jira.User{
                AccountID: "<username>",
            },
            Description: "Test Issue",
            Type: jira.IssueType{
                Name: "Story",
            },
            Project: jira.Project{
                Key: "ABC",
            },
            Summary: "Just a demo issue",
        },
    }
    issue, _, err := jiraClient.Issue.Create(&i)
    if err != nil {
        log.Println("ERROR: ", err)
    }

    fmt.Printf("%s: %+v\n", issue.Key, issue.Fields.Summary)
    fmt.Println(issue)
}

getting an error while running this piece of code

github-actions[bot] commented 3 years ago

Hi! Thank you for taking the time to create your first issue! Really cool to see you here for the first time. Please give us a bit of time to review it.

andygrunwald commented 3 years ago

@sonalp123 Thanks for raising the issue. Would you mind adding a few more information about your environment?

  1. Which JIRA Version are you using?
  2. Cloud Version or On-Premise?
  3. Which Go version + Operating System are you using?
  4. Would you mind pasting the complete error message? (to see in which line the panic is thrown)
sonalp123 commented 3 years ago

@andygrunwald :

  1. jira version-8.5.7
  2. on prem
  3. go version is 1.15.3, mac
  4. updated in the post - issue is on fmt.Printf("%s: %+v\n", issue.Key, issue.Fields.Summary)
andygrunwald commented 3 years ago

Thanks for all the information @sonalp123. We will have a look at this when we have a bit of time for it.

manuelbcd commented 3 years ago

Hello @sonalp123 I think we know what is happening. The issue.Fields array is not present in creation response by default so you are trying to read a non populated field. Please remove "issue.Fields.xxx", you can print issue.xxx without any problem. If you want to get the .Fields array you will need to request the issue using GET after the creation in two different actions (there are many examples of GET here, if you need some help please let us know)

In older versions of Jira it was possible to access to .Field.xxxx responses in creation action, but it is not possible anymore.

Hope this clarifies the problem

manuelbcd commented 3 years ago

Hi @sonalp123 would you be so kind to confirm that your issue is resolved so that we can close it? Thank you

aspirin420 commented 3 years ago

@manuelbcd I have the same error: "request failed. Please analyze the request body for more details. Status code: 400". The panic occured in client.Issue.Create(&i), not in "issue.Fields.xxx". Hope for reply.

Hello @sonalp123 I think we know what is happening. The issue.Fields array is not present in creation response by default so you are trying to read a non populated field. Please remove "issue.Fields.xxx", you can print issue.xxx without any problem. If you want to get the .Fields array you will need to request the issue using GET after the creation in two different actions (there are many examples of GET here, if you need some help please let us know)

In older versions of Jira it was possible to access to .Field.xxxx responses in creation action, but it is not possible anymore.

Hope this clarifies the problem

aspirin420 commented 3 years ago

@manuelbcd I have the same error: "request failed. Please analyze the request body for more details. Status code: 400". The panic occured in client.Issue.Create(&i), not in "issue.Fields.xxx". Hope for reply.

Hello @sonalp123 I think we know what is happening. The issue.Fields array is not present in creation response by default so you are trying to read a non populated field. Please remove "issue.Fields.xxx", you can print issue.xxx without any problem. If you want to get the .Fields array you will need to request the issue using GET after the creation in two different actions (there are many examples of GET here, if you need some help please let us know) In older versions of Jira it was possible to access to .Field.xxxx responses in creation action, but it is not possible anymore. Hope this clarifies the problem

my jira version is 8.6.1 ,go version is the latest

sonalp123 commented 3 years ago

Hi,

The issue is resolved. we can close the issue.

Regards,

Sonal Patil

On Tue, Sep 14, 2021 at 3:30 AM Shicheng Wang @.***> wrote:

@manuelbcd https://github.com/manuelbcd I have the same error: "request failed. Please analyze the request body for more details. Status code: 400". The panic occured in client.Issue.Create(&i), not in "issue.Fields.xxx". Hope for reply.

Hello @sonalp123 https://github.com/sonalp123 I think we know what is happening. The issue.Fields array is not present in creation response by default so you are trying to read a non populated field. Please remove "issue.Fields.xxx", you can print issue.xxx without any problem. If you want to get the .Fields array you will need to request the issue using GET after the creation in two different actions (there are many examples of GET here, if you need some help please let us know) In older versions of Jira it was possible to access to .Field.xxxx responses in creation action, but it is not possible anymore. Hope this clarifies the problem

my jira version is 8.6.1 ,go version is the latest

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/andygrunwald/go-jira/issues/376#issuecomment-919024970, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABI53UIL3WI2KTECLSPEA43UB4P5LANCNFSM44XKUSYA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

aspirin420 commented 3 years ago

Hi, The issue is resolved. we can close the issue. Regards, Sonal Patil ᐧ On Tue, Sep 14, 2021 at 3:30 AM Shicheng Wang @.***> wrote: @manuelbcd https://github.com/manuelbcd I have the same error: "request failed. Please analyze the request body for more details. Status code: 400". The panic occured in client.Issue.Create(&i), not in "issue.Fields.xxx". Hope for reply. Hello @sonalp123 https://github.com/sonalp123 I think we know what is happening. The issue.Fields array is not present in creation response by default so you are trying to read a non populated field. Please remove "issue.Fields.xxx", you can print issue.xxx without any problem. If you want to get the .Fields array you will need to request the issue using GET after the creation in two different actions (there are many examples of GET here, if you need some help please let us know) In older versions of Jira it was possible to access to .Field.xxxx responses in creation action, but it is not possible anymore. Hope this clarifies the problem my jira version is 8.6.1 ,go version is the latest — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#376 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABI53UIL3WI2KTECLSPEA43UB4P5LANCNFSM44XKUSYA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.


how resolve this ? can u give the solution?

manuelbcd commented 3 years ago

@sonalp123 would you be so kind to share with us what did the trick to resolve it?

andygrunwald commented 2 years ago

Hey,

I am very sorry that this issue has been open for a long time with no final solution. We work on this project in our spare time, and sometimes, other priorities take over. This is the typical open source dilemma.

However, there is news: We are kicking off v2 of this library 🚀

To provide visibility, we created the Road to v2 Milestone and calling for your feedback in https://github.com/andygrunwald/go-jira/issues/489

The development will take some time; however, I hope you can benefit from the changes. If you seek priority development for your issue + you like to sponsor it, please contact me.

What does this mean for my issue?

We will work on this issue indirectly. This means that during the development phase, we aim to tackle it. Maybe in a different way like it is currently handled. Please understand that this will take a while because we are running this in our spare time.

Final words

Thanks for using this library. If there is anything else you would like to tell us, let us know!