Skip to content

[confmap] Return nil map if original map was nil #13161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

mx-psi
Copy link
Member

@mx-psi mx-psi commented Jun 5, 2025

Description

Amends ToStringMap so that it returns map[string]any(nil) if the map used to create this Conf was nil. Currently it returns an empty map.

I consider this a bug since, while not explicitly undocumented, I would expect the following two properties to be true, and they were not before this change:

  1. For any map m without expandedValues, NewFromStringMap(m).ToStringMap(m) == m
  2. For any map m without expandedValues and any path referencing an existing key in m with a map[string]any value, NewFromStringMap(m).Sub(path) == m[path[0]][path[1]][...][path[N]]

Link to tracking issue

I need this to be able to distinguish between

foo:
   bar:

and

foo:
  bar: {}

which currently have different behaviors when mapping to pointers.

The goal is to be able to do #13168

@mx-psi mx-psi requested review from evan-bradley and a team as code owners June 5, 2025 12:13
@mx-psi mx-psi marked this pull request as draft June 5, 2025 12:13
Copy link

codecov bot commented Jun 5, 2025

Codecov Report

Attention: Patch coverage is 68.96552% with 9 lines in your changes missing coverage. Please review.

Project coverage is 91.27%. Comparing base (c9aaed8) to head (9952b85).

Files with missing lines Patch % Lines
confmap/confmap.go 68.96% 7 Missing and 2 partials ⚠️

❌ Your patch check has failed because the patch coverage (68.96%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13161      +/-   ##
==========================================
- Coverage   91.29%   91.27%   -0.02%     
==========================================
  Files         509      509              
  Lines       28735    28759      +24     
==========================================
+ Hits        26233    26251      +18     
- Misses       1988     1993       +5     
- Partials      514      515       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mx-psi mx-psi marked this pull request as ready for review June 6, 2025 09:35
Comment on lines +232 to +239
} else if v.Value == nil {
// If the value is nil, return a new empty Conf.
c := New()
c.isNil = true
return c, nil
}
// override data with the original value to make the error message more informative.
data = v.Value
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is tested in the nil_test.go file in the end to end tests, but CodeCov doesn't know that since that is a separate module

Copy link
Contributor

@jade-guiton-dd jade-guiton-dd Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about that? Running the test in a debugger, it looks like data is never an expandedValue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry nevermind, looks like I was looking at the wrong test in that file.

Copy link
Contributor

@jade-guiton-dd jade-guiton-dd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a few nitpicks, although I would want a second approval, in case others have strong objections to returning nil from a function which did not previously, even if it causes no issues in contrib.

@mx-psi
Copy link
Member Author

mx-psi commented Jun 6, 2025

LGTM, just a few nitpicks, although I would want a second approval, in case others have strong objections to returning nil from a function which did not previously, even if it causes no issues in contrib.

Yes, I will wait. The obvious alternative would be to keep the behavior of ToStringMap as it currently is and add a separate IsNil method

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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy