config: show missing section error correctly
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
		
							parent
							
								
									4d77bd8f25
								
							
						
					
					
						commit
						f5d2fd6190
					
				@ -69,6 +69,7 @@ public final class Config {
 | 
				
			|||||||
        final Collection<String> peerLines = new ArrayList<>();
 | 
					        final Collection<String> peerLines = new ArrayList<>();
 | 
				
			||||||
        boolean inInterfaceSection = false;
 | 
					        boolean inInterfaceSection = false;
 | 
				
			||||||
        boolean inPeerSection = false;
 | 
					        boolean inPeerSection = false;
 | 
				
			||||||
 | 
					        boolean seenInterfaceSection = false;
 | 
				
			||||||
        @Nullable String line;
 | 
					        @Nullable String line;
 | 
				
			||||||
        while ((line = reader.readLine()) != null) {
 | 
					        while ((line = reader.readLine()) != null) {
 | 
				
			||||||
            final int commentIndex = line.indexOf('#');
 | 
					            final int commentIndex = line.indexOf('#');
 | 
				
			||||||
@ -86,6 +87,7 @@ public final class Config {
 | 
				
			|||||||
                if ("[Interface]".equalsIgnoreCase(line)) {
 | 
					                if ("[Interface]".equalsIgnoreCase(line)) {
 | 
				
			||||||
                    inInterfaceSection = true;
 | 
					                    inInterfaceSection = true;
 | 
				
			||||||
                    inPeerSection = false;
 | 
					                    inPeerSection = false;
 | 
				
			||||||
 | 
					                    seenInterfaceSection = true;
 | 
				
			||||||
                } else if ("[Peer]".equalsIgnoreCase(line)) {
 | 
					                } else if ("[Peer]".equalsIgnoreCase(line)) {
 | 
				
			||||||
                    inInterfaceSection = false;
 | 
					                    inInterfaceSection = false;
 | 
				
			||||||
                    inPeerSection = true;
 | 
					                    inPeerSection = true;
 | 
				
			||||||
@ -104,7 +106,7 @@ public final class Config {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        if (inPeerSection)
 | 
					        if (inPeerSection)
 | 
				
			||||||
            builder.parsePeer(peerLines);
 | 
					            builder.parsePeer(peerLines);
 | 
				
			||||||
        else if (!inInterfaceSection)
 | 
					        if (!seenInterfaceSection)
 | 
				
			||||||
            throw new BadConfigException(Section.CONFIG, Location.TOP_LEVEL,
 | 
					            throw new BadConfigException(Section.CONFIG, Location.TOP_LEVEL,
 | 
				
			||||||
                    Reason.MISSING_SECTION, null);
 | 
					                    Reason.MISSING_SECTION, null);
 | 
				
			||||||
        // Combine all [Interface] sections in the file.
 | 
					        // Combine all [Interface] sections in the file.
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user