msgraph-sdk-go icon indicating copy to clipboard operation
msgraph-sdk-go copied to clipboard

Basic examples in documentation are wrong

Open weeco opened this issue 1 year ago • 4 comments
trafficstars

Hello, I find this library rather hard to use and noticed that the basic examples as documented are not working. For example the following snippet in your README documents the generic error handling as follows:

func printOdataError(err error) {
	switch err.(type) {
	case *odataerrors.ODataError:
		typed := err.(*odataerrors.ODataError)
		fmt.Printf("error:", typed.Error())
		if terr := typed.GetError(); terr != nil {
			fmt.Printf("code: %s", *terr.GetCode())
			fmt.Printf("msg: %s", *terr.GetMessage())
		}
	default:
		fmt.Printf("%T > error: %#v", err, err)
	}
}

There's no typed.GetError() method anymore. I believe this was a breaking change and exist before. Today there's a typed.Error() method which returns a string.

weeco avatar Apr 15 '24 13:04 weeco

Hi @weeco Thanks for using the SDK and for reaching out. I'm not sure I understand what the issue is here? there is a odataerror error method

Could you clarify please?

baywet avatar Apr 15 '24 13:04 baywet

Apologies, I did a typo in one sentence - I correct it now. The missing method that you are referring to in your Readme is GetError()

Right there's an Error method here - which returns a string (see my initial post), but if you look at the copied snippet I took from your README you can see that it's using a GetError() method which does not exist.

weeco avatar Apr 15 '24 14:04 weeco

Thanks for clarifying. I believe it's now meant to be "GetErrorEscaped", it's ugly but it's to avoid collisions with native "Error" symbol. Would you be willing to submit a pull request to correct that please?

baywet avatar Apr 17 '24 12:04 baywet

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

I ran into the same issue as described. Thanks for the declaration. :) I'm glad to help update the documentation with this pull request: https://github.com/microsoftgraph/msgraph-sdk-go/pull/802

JacieChao avatar Nov 12 '24 09:11 JacieChao