go-jira icon indicating copy to clipboard operation
go-jira copied to clipboard

Error while creating jira story

Open sonalp123 opened this issue 4 years ago • 11 comments

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

sonalp123 avatar May 11 '21 23:05 sonalp123

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.

github-actions[bot] avatar May 11 '21 23:05 github-actions[bot]

@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)

andygrunwald avatar May 12 '21 14:05 andygrunwald

@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)

sonalp123 avatar May 12 '21 15:05 sonalp123

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

andygrunwald avatar May 14 '21 13:05 andygrunwald

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 avatar May 18 '21 11:05 manuelbcd

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

manuelbcd avatar May 26 '21 07:05 manuelbcd

@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 avatar Sep 14 '21 10:09 aspirin420

@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

aspirin420 avatar Sep 14 '21 10:09 aspirin420

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.

sonalp123 avatar Sep 14 '21 16:09 sonalp123

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?

aspirin420 avatar Sep 15 '21 11:09 aspirin420

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

manuelbcd avatar Sep 27 '21 14:09 manuelbcd

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!

andygrunwald avatar Aug 21 '22 14:08 andygrunwald