pr0pz/scene-release-parser

section.match is not a function

Closed this issue · 5 comments

Hello I detect a problem, I developed a react application, everything works well until the announcement of a release which has this name Naili-Juste_Un_Petale..-WEB-FR-2024-OND, then react returns this message :

`Uncaught runtime errors:
×
ERROR
section.match is not a function
TypeError: section.match is not a function
    at guessTypeBySection (http://localhost:3000/static/js/bundle.js:52320:33)
    at parseType (http://localhost:3000/static/js/bundle.js:52180:20)
    at ReleaseParser (http://localhost:3000/static/js/bundle.js:53362:3)
    at ReleaseCard (http://localhost:3000/static/js/bundle.js:1980:83)
    at renderWithHooks (http://localhost:3000/static/js/bundle.js:24028:22)
    at mountIndeterminateComponent (http://localhost:3000/static/js/bundle.js:27312:17)
    at beginWork (http://localhost:3000/static/js/bundle.js:28608:20)
    at HTMLUnknownElement.callCallback (http://localhost:3000/static/js/bundle.js:13624:18)
    at Object.invokeGuardedCallbackDev (http://localhost:3000/static/js/bundle.js:13668:20)
    at invokeGuardedCallback (http://localhost:3000/static/js/bundle.js:13725:35)`

it looks like this is happening at your function level :

`const guessTypeBySection = ( section ) =>
	{
		let type = ''

		// No Section, no chocolate!
		if ( section )
		{
			// Loop all types
			for ( const typeParentKey in patterns.TYPE )
			{
				let typeValue = patterns.TYPE[ typeParentKey ]

				// Transform every var to array, so we can loop
				if ( !Array.isArray( typeValue ) )
					typeValue = [ typeValue ]

				// Loop all type patterns
				for ( const value of typeValue )
				{
					// Match type
					let matches = section.match( ( '/' + value + '/i' ).toRegExp() )

					// Match found, set type parent key as type
					if ( matches )
					{
						type = typeParentKey
						break
					}
				}

				if ( type !== '' ) break;
			}
		}

		return type
	}`

Thank you for the correction.

Hi @Emellane ,

I can't really reproduce the issue this time.
ReleaseParser takes two arguments: releaseName (required) and section (optional).
Section is an empty string by default.

Which section is passed from your DB with the release you're naming?

My first guess would be to make the if statement a little bit clearer:
ReleaseParser.js - line 1010
old: if ( section )
new: if ( section !== '' ) (only non empty strings)

Can you replace the line and see if the error is fixed?

Hello pr0pz,

Thank you for your help, it is really appreciated.

after making the modification to line "1010" if (section !== '')

image

the error still occurs,

here is the answer for the releases in question:

[
     {
         "id": 12025,
         "channel": "#relay-test",
         "section": "MP3-WEB",
         "release_name": "Naili-Juste_Un_Petale..-WEB-FR-2024-OND",
         "pretime": "1704889200.9504368",
         "team": "OND",
     }
]

To reproduce this bug I perform a search Naili-Juste_Un_Petale..-WEB-FR-2024-OND with the site's search bar, it then returns the error.

image

I think the error comes from the name of the release not from the section, more precisely from the two ".." which follow in the name of the release.

When I do a new search for a releases which has the same section, but no double "." It works, it returns the requested information, example:

Query URL:
http://localhost:3003/data?search=Uncled-Reborn-(SUR202)-SINGLE-WEB-2024-PTC

Answer:

[
    {
        "id": 14704,
        "channel": "#relay-test",
        "section": "MP3-WEB",
        "release_name": "Uncled-Reborn-(SUR202)-SINGLE-WEB-2024-PTC",
        "pretime": "1704985474.1637263",
        "team": "PTC",
    }
]

returning a console.log:
image

on the site:
image

then the site displays the information with this release, but not with certain releases which contain double "."

Here is a piece of my code for using release-parser:

image

if you need more information, I remain available, thank you again.

Thanks for more input.

section.match is throwing the error, so I think it might not be the release name.
match is the regex function of the section (which should be a string).
This only works for strings and not for other object types.

I tested it again and the errors appears when section is something else but a string (int, object, whatever).
Try again replacing line 1010 with this code:
if ( typeof section === 'string' && section !== '' )

We have to make sure, that section is a string.
I think somewhere on the way, in your code, your section var ("section": "MP3-WEB") gets converted to something else
Try again with the line and make sure to convert your used variable to a string before passing it as section to the parser.

The problem seems resolved, it no longer generates the error after modifying line 1010

image

This time it correctly displays the search return without generating the error.

image

Just one thing I noticed the "Type" doesn't match:

image

A huge thank you for your responsiveness and for this superb project, I will be able to move forward on my PREDB project.

I wish you the best, and come back if I detect any new errors ;)

Awesome, glad it got solved :)

Thank you very much, this is my first npm package so I really need the feedback.
Send me a link when your predb is ready to rumble, excited to see the result.

I'll put the fix in the next release.