Skip to content

Conversation

@Rangababu-R
Copy link
Contributor

Sample code for the error messages by adding path to it

func (obj *prefixConfig) FromJson(value string) error {
	opts := protojson.UnmarshalOptions{
		AllowPartial:   true,
		DiscardUnknown: false,
	}
	uError := opts.Unmarshal([]byte(value), obj.Msg())
	if uError != nil {
		return fmt.Errorf("unmarshal error %s", strings.Replace(
			uError.Error(), "\u00a0", " ", -1)[7:])
	}
	err := obj.validateFromText("prefixConfig.FromJson()")
	if err != nil {
		return err
	}
	return nil
}

func (obj *prefixConfig) validateFromText(path string) error {
	obj.validateObj(true, path)
	return validationResult()
}

func (obj *prefixConfig) Validate() error {
	obj.validateObj(false, "prefixConfig.Validate()")
	return validationResult()
}

func (obj *prefixConfig) validateObj(set_default bool, path string) {
	if set_default {
		obj.setDefault()
	}

	// RequiredObject is required
	if obj.obj.RequiredObject == nil {
		validation = append(
			validation,
			fmt.Sprintf("PrefixConfig.required_object is a required field from path %s", path))
	}

	if obj.obj.RequiredObject != nil {
		obj.RequiredObject().validateObj(
			set_default, fmt.Sprintf("%s.RequiredObject", path))
	}

@Rangababu-R
Copy link
Contributor Author

addressed: #221

@Rangababu-R Rangababu-R reopened this Dec 15, 2021
@Rangababu-R Rangababu-R marked this pull request as draft January 10, 2022 10:24
@Rangababu-R
Copy link
Contributor Author

merged into #281

@Vibaswan Vibaswan deleted the change_of_error_msgs branch June 18, 2025 10:17
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