Skip to content

t128_tank: stream from the beginning if parsing the index fails#82

Merged
gregschrock merged 1 commit intorelease-128tech-1.22.100-multiarch-supportfrom
gschrock/I95-62311-t128-tank-handle-empty
Sep 17, 2025
Merged

t128_tank: stream from the beginning if parsing the index fails#82
gregschrock merged 1 commit intorelease-128tech-1.22.100-multiarch-supportfrom
gschrock/I95-62311-t128-tank-handle-empty

Conversation

@gregschrock
Copy link
Collaborator

@gregschrock gregschrock commented Sep 11, 2025

I95-62311

Description

There are a couple cases when reading the index file we might return an error indicating that it failed and why.

  1. file doesn't exist isn't an error, but other failures to read are
  2. failing to parse the content of the file

The intention here was to provide information, but not to fail. The default index should be used when these errors occur. However, the calling code was written to check for the error and "fail" if observed. Instead, the failure should be logged and the process should continue. The code is updated to behave as described.

Testing: https://github.com/Juniper-SSN/ssr/pull/18009

The index code for reference:

func (r *Reader) getIndex(indexPath string, defaultIndex index) (index, error) {
	if indexPath == "" {
		r.log.Debugf("index file path not provided, starting with default index %s", defaultIndex.string())
		return defaultIndex, nil
	}
	content, err := os.ReadFile(indexPath)
	if errors.Is(err, os.ErrNotExist) {
		r.log.Debugf("index file %s does not exist, starting with default index %s", indexPath, defaultIndex.string())
		return defaultIndex, nil

	} else if err != nil {
		return defaultIndex, fmt.Errorf("encountered error reading index file, starting with default index %s: %s", defaultIndex.string(), err)
	}
	newContent := strings.Split(string(content), "\n")[0]
	r.log.Debugf("found '%s' in index file", newContent)
	index, err := newIndex(newContent)
	if err != nil {
		return defaultIndex, fmt.Errorf("encountered error while parsing index file content, starting with default index %s: %s", defaultIndex.string(), err)
	}

	return index, nil
}

Copy link

@shriyanshk128T shriyanshk128T left a comment

Choose a reason for hiding this comment

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

Should we do some manual testing just to make sure this doesn't break anything?

@gregschrock
Copy link
Collaborator Author

Added testing here: https://github.com/Juniper-SSN/ssr/pull/18009

@gregschrock gregschrock merged commit c94be0d into release-128tech-1.22.100-multiarch-support Sep 17, 2025
2 checks passed
@gregschrock gregschrock deleted the gschrock/I95-62311-t128-tank-handle-empty branch September 17, 2025 13:51
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